@moevis/restpower
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

RestPower: a new way to write a http client

import "reflect-metadata";
import { API, RestPower, Get, Header, Path, Post, Query, R } from "restpower";

@API({ prefix: "/api/user" })
class UserService extends RestPower {
  @Get("/profile")
  profile() {
    return R<{ name: string }>();
  }

  @Get("/{id}/profile")
  userProfile(@Path("id") _user_id: string) {
    return Promise.resolve({} as IResp);
  }

  @Get("/{0}/profile")
  userProfile2(_user_id: string) {
    return R<{ data: string }>();
  }

  @Get("/posts")
  posts(
    @Query("key") _key: string,
    @Query() _paginator: { pageSize: number; page: number }
  ) {
    return R<{}>();
  }

  @Post("/login")
  login(@Body() _user: IUser) {
    return R<{}>();
  }

  @Post("/any")
  anyRoute(
    @Body() _body: { name: string },
    @Query() _q: { age: number },
    @Header("tttt") _h: string
  ) {
    return R<{}>();
  }
}

interface IUser {
  user: string;
  password: string;
}

const service = new UserService();

service.userProfile("uid");

Readme

Keywords

none

Package Sidebar

Install

npm i @moevis/restpower

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

27.2 kB

Total Files

23

Last publish

Collaborators

  • moevis