ws-rs
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

TypeScript WS RS

It's an experiment to test the idea.

Is it possible to build HTTP clients using annotations similar to JAVA WS RS in TypeScript.

Use

$ yarn install ws-rs

Example

import { buildClient, GET, Path, PathParam, QueryParam } from 'ws-rs';

interface User {
    id: string;
    name: string;
    active: 'yes' | 'no';
}

@Path('/users')
class UsersResource {
    @GET
    @Path('/{id}')
    getUser(@PathParam('id') id: string, @QueryParam('active') active: string): Promise<User> {
        return null;
    }
}

const client = buildClient(UsersResource, 'http://localhost:8000');

client.getUser('4', 'yes')
    .then((user) => {
        console.log(user);
    })
    .catch((error) => {
        console.error(error);
    });

Develop

Install dev-dependencies

$ yarn install

Build library

$ yarn build:lib

Build and run demo

$ yarn build:demo
$ yarn serve:demo

Readme

Keywords

none

Package Sidebar

Install

npm i ws-rs

Weekly Downloads

1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • devoto13