Skip to content

Helper API for express (success, badRequest, unauthorized, forbidden, notFound, unsupportedAction, invalid, error)

License

Notifications You must be signed in to change notification settings

bytesleo/express-easy-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-easy-helper

Simple helper module for express

Installation

yarn

yarn add express-easy-helper

npm

npm install express-easy-helper --save

Usage

import { success, unauthorized, forbidden, error } from "express-easy-helper";
import express from "express";
const app = express();

// success
app.get("/", (req, res) => {
  success(res, { hello: "world" });
});

// unauthorized
app.get("/unauthorized", (req, res) => {
  unauthorized(res);
});

// forbidden
app.get("/protected", (req, res) => {
  forbidden(res);
});

// error
app.get("/error", (req, res) => {
  error(res);
});

Method's

// 200
success(res);

// 400
badRequest(res);

// 401
unauthorized(res);

// 403
forbidden(res);

// 404
notFound(res);

//405
unsupportedAction(res);

//422
invalid(res);

// 500
error(res);

Options

// Basic
success(res);

// Code status
success(res, 201);

// Data
success(res, { hello: "world" });

// Code status and data
success(res, 201, { hello: "world" });

License

MIT © Leonardo Rico

About

Helper API for express (success, badRequest, unauthorized, forbidden, notFound, unsupportedAction, invalid, error)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published