Skip to main content

farrow-federation

A aggregation tool for farrow-api.

It expands from farrow-api-service and get them together to a new and fully-cover services.

Install

yarn add farrow-federation

Frist Look

import { Http } from "farrow-http";
import { Federation } from "farrow-federation";

const http = Http();

const service = await Federation([
{
// anthor farrow-api-server entry
url: "http://localhost:3001/api/todo",
namespace: "todo",
},
]);

http.use(service);

http.listen(3000);

In this demo, the federation service only group one service that is at http://localhost:3001/api/todo. But as you might expect, it can group more service created by farrow-api-service. It also be a service, so it can group themselves.

Services

export type ApiService = {
url: string;
namespace: string;
};

export type ApiServices = ApiService[];

this option for you to pass the all service you want to get together.

The url is the service entry and the namespace is the namespace of this service entry in current federation.

Options

fetch

fetch?: (input: RequestInfo, init?: RequestInit | undefined) => Promise<globalThis.Response>

For customing fetch.

Default: node-fetch.

fetcher

fetcher?: ((request: ApiSingleRequest) => Promise<ApiResponseSingle>) &
((request: ApiIntrospectionRequest) => Promise<ApiResponseSingle>) &
((request: ApiBatchRequest) => Promise<ApiResponseBatch>)

For customing the function which sends the calling request.

Default: createFetcher

polling

polling?: boolean

Polling switch.

Default: false.

pollingInterval

pollingInterval?: number

Polling interval time(ms).

Default: 3000.

errorStack

errorStack?: boolean

Should display error.stack or not.

Default: process.env.NODE_ENV !== 'production'.

strict

strict: true;

Should throw error when connect to services or not.

Default: true

Suggestion: false in development, true in production.

Learn more

Relative Module