npm install endpoint-client
yarn add endpoint-client
import { Endpoint } from "endpoint-client";
export type GetEndpointParameter = {
pathItem: string;
bodyItem: string;
queryItem: string;
};
export type GetEndpointResponse = {
name: string;
};
export const GetEndpoint: Endpoint<GetEndpointParameter, GetEndpointResponse> =
{
method: "GET",
path: (e) => `/endpoint/${e.pathItem}`,
bodyParams: ["bodyItem"],
pathParams: ["pathItem"],
queryParams: ["queryItem"],
};
import { EndpointClient } from "endpoint-client";
import { GetEndpoint } from "...";
export class Client extends EndpointClient {
readonly endpoint = {
get: this.endpointBuilder(GetEndpoint),
};
}
export const client = new Client({
baseUrl: "https://api.example/com",
});
...
const res = await client.endpoint.get({
pathItem: 'a',
bodyItem: 'b',
queryItem: 'c',
});
console.log(res);
...