npm

Join us for the "JavaScript Supply Chain Security" tech talk, presented by VP of Security, Adam Baldwin. 6/20 at 10am PT.Sign up here »

express-mate

1.6.6 • Public • Published

express-mate

Helper library that makes your life a little easier when working with Express REST APIs

Router

The Router is a helper tool which wraps the existing Express Router for helpful functionality. It takes a verbosity over terseness approach and is designed to make large routing files clearer.

const GET = Router.createRoutes(RequestType.GET, [
  {
    path: '/',
    steps: [
      async (req, res) => {
        res.end('Hello World!');
      }
    ]
  },
]);
 
const PATCH = Router.createRoutes(RequestType.PATCH, [
  {
    path: '/',
    steps: [
      async (req, res) => {
        res.end('Hello PATCH!');
      }
    ]
  }
]);
 
const POST = Router.createRoutes(RequestType.POST, [
  {
    path: '/',
    steps: [
      async (req, res) => {
        res.end('Hello POST!');
      }
    ]
  }
]);
 
const MISC = [
  {
    type: RequestType.GET,
    path: '/hello',
    steps: []
  }
];
 
const router = new Router(GET, PATCH, POST, MISC);

Response Objects

All response objects follow the JSend guidelines.

ApiSuccess

Successful response!

{
  "status": "success",
  "data": "hello world!"
}

ApiError

Standard error response.

{
  "status": "error",
  "message": "You left the oven on!",
  "data": "[Error: You left the oven on!]"
}

ApiUnauthorized

Unsuccessful authentication.

{
  "status": "unauthenticated",
  "message": "Authentication required"
}

ApiForbidden

Successful authentication without required permissions.

{
  "status": "forbidden",
  "message": "Access denied"
}

ApiFail

Commonly used for validation error responses.

{
  "status": "bad request",
  "data": {
    "email": "Email is required"
  }
}

ApiNotFound

Data requested does not exist.

{
  "status": "not found"
}

Keywords

none

install

npm i express-mate

Downloadsweekly downloads

36

version

1.6.6

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability