endpoint-client
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

endpoint-client

타입 안전한 API 엔드포인트 추상화

MIT License MIT License


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);
...

Readme

Keywords

none

Package Sidebar

Install

npm i endpoint-client

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

73.2 kB

Total Files

43

Last publish

Collaborators

  • phw3071