Skip to content

backrunner/response-wrap

Repository files navigation

response-wrap

Simple response wrapper classes for Node.js servers.

This package was created by create-a-typescript-lib.

Usage

Step 1: Install this package

npm install response-wrap -S

Step 2: Import and use it

import Koa from 'koa';
import KoaRouter from '@koa/router';
import { Response, SuccessResponse, ErrorResponse } from 'response-wrap';

interface ResponsePayload {
  token: string;
}

const app = new Koa();
const router = new Router();

router.get('/res', (ctx, next) => {
  ctx.body = new Response<ResponsePayload>(
    {
      token: 'abc123',
    },
    0,
    'success',
  );
});

router.get('/error', (ctx, next) => {
  ctx.body = new ErrorResponse(-1, 'internal server error');
});

router.get('/successRes', (ctx, next) => {
  ctx.body = new SuccessResponse<ResponsePayload>({
    token: 'abc123',
  });
});

License

MIT

About

Simple response wrapper classes for Node.js servers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published