endpoint-client
v0.1.1
Published
endpoint Client
Downloads
18
Readme
install
npm install endpoint-client
yarn add endpoint-client
Usage
엔드포인트 정의
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}`,
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);
...