1.0.0 • Published 3 years ago

easy-api-interface v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

easy-api-interface

Write api interface with decorators

import { getInstance, Service, Post, Path, FieldMap } from 'easy-api-interface';

@Service('users')
class User {
    @Post('/:id')
    queryData(@Path('id') _userId: string, @FieldMap() _data: any): Promise<any> {
        return {} as Promise<any>
    };
}
const userService = getInstance(User, {
    baseUrl: 'https://api.github.com/',
    adapter: (url, options) => {
        return fetch(url, {
            method: options.method,
            body: options.method === 'GET' ? null : JSON.stringify(options.params)
        });
    },
});
userService.queryData("w-rudolph", { x: '1', y: '2' }).then(console.log);
1.0.0

3 years ago