An elegant way to write restful clients


This projects aims to be foundation component for the rest of @t2ee projects. It provides dependency injection and auto configuration functionalities.


npm i reflect-metadata @t2ee/core @t2ee/restful -S


Basic Example

interface Repository {
    id: number;
    name: string;

class GithubRepo {
    listUserRepos(@Path('username') username: string, @Query('type') type): Promise<Repository[]> {return null}

const builder = new RestfulService().baseUrl('https://api.github.com/');
const client = builder.create(GithubRepo);

const repos = await client.listUserRepos('t2ee', 'all');

POST Request

createUser(@Body user: User): Promise<User> {return null}

Form Example

createUser(@Field('name') name, @Field('age') age): Promise<User> {return null}

Multipart Example

upload(@Field('file_name') name: string, @Part('file') file: string | Buffer): Promise<void>;

Static Headers

@Headers('Cookie', '123')
@Headers({ 'Cookie': '345' })
get(): Promise<User> {return null}


Decorators for function arguments


Body to be sent when sending as a JSON request.


Value for parameters in path


A form request field, or multipart request field.


Value in query


Files to be uploaded (either path to file or a buffer) when issuing a multipart request

Vaue in Header


An object contains all the form/multipart request fields.


An object for query


An object for header

Decorators for functions

@GET(), @POST(), @PUT(), @DELETE()

Declare url and http method.


Provide headers to be sent


An url encoded form request


A multipart request