Frontend Integrations

Ready-to-use snippets to wire up leading frontend frameworks to your ultra-fast API backend seamlessly.

1. Angular (TypeScript)

Angular natively employs RxJS `HttpInterceptor` abstractions, making connecting to your GO-DUCK APIs simple.

Note: We bypass typical manual HTTP Auth mapping by using Angular's pre-built keycloak-angular ecosystem package.

Creating a Service for Entity

import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common';
import { Observable } from 'rxjs';

export interface Entity {
  id: number;
  name: any;
  domain: any;
  description: any;
  metadata: any;
}

@Injectable({ providedIn: 'root' })
export class EntityService {
  private apiUrl = 'http://localhost:8080/api/entitys';

  constructor(private http: HttpClient) {}

  // Standard REST Fetch with Pagination Parameters
  getAll(page: number = 1, pageSize: number = 10): Observable<any> {
    let params = new HttpParams()
        .set('page', page.toString())
        .set('pageSize', pageSize.toString());
    return this.http.get<any>(this.apiUrl, { params });
  }

  // Example: Using the powerful Generic Search RPC Engine
  search(queryField: string, operator: string, value: string): Observable<any> {
    let params = new HttpParams().set(queryField, \`\${operator}.\${value}\`);
    return this.http.get<any>('http://localhost:8080/api/rpc/entity', { params });
  }
}

2. Flutter (Dart)

Connecting a cross-platform mobile app requires managing state efficiently. Here's a raw HTTP Dart integration model you can bind to Provider, Riverpod, or BLoC patterns seamlessly over your Keycloak environment.

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter_secure_storage/flutter_secure_storage.dart';

class ApiProvider {
  static const String baseUrl = "http://localhost:8080/api/entitys";
  final storage = const FlutterSecureStorage();

  // Retrieve Keycloak Bearer token from secure storage
  Future<Map<String, String>> _getHeaders() async {
    String? token = await storage.read(key: 'jwt_token');
    return {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer $token',
      'X-Tenant-ID': 'default', // If using Multi-Tenancy module
    };
  }

  // Fetch API collection
  Future<List<dynamic>> fetchEntitys() async {
    final response = await http.get(Uri.parse(baseUrl), headers: await _getHeaders());
    if (response.statusCode == 200) {
      final data = json.decode(response.body);
      return data['results']; 
    } else {
      throw Exception('Failed to load data. Res code: \${response.statusCode}');
    }
  }
}

3. WSO2 API Manager Integration

GO-DUCK generated APIs can automatically register themselves with a WSO2 API Manager instance on startup. This uses the WSO2 Publisher REST API to import your dynamically generated OpenAPI 3.0 specs.

Standard API Gateway Discovery

For external gateways (Kong, Apigee) and ecosystems like JHipster and Spring Boot, your microservice natively exposes its OpenAPI JSON at the standard /v3/api-docs endpoint. Legacy systems can still use /swagger.json.

WSO2 Configuration: Enable this by adding the wso2 block to your config.yaml.

go-duck:
  integrations:
    wso2:
      enabled: true
      publisher-url: "https://localhost:9443/api/am/publisher/v3"
      client-id: "YOUR_WSO2_CLIENT_ID"
      client-secret: "YOUR_WSO2_CLIENT_SECRET"
      gateway-environments:
        - "Production"
        - "Sandbox"