2.2.0 • Published 2 years ago

express-standard-http-responses v2.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Foreword

Hi 👋 !
This package has the only purpose to format the responses for express.

Installation

npm install express-standard-http-responses --save

Environment used

npm@8.5.1
node@14.16.0

Example

import {httpResponses} from "express-standard-http-responses";
import * as express from 'express';

const app = express();
const port = process.env.port || 3000;

app.listen(port, () => {
    console.log(`Listening at http://localhost:${port}`)
});

app.get('/test', (req, res) => {
    return httpResponses(res).body({body: {nested: "content"}}).message('Information').created();
});

Response example

{
  "body": {
    "nested": "content"
  },
  "message": "Information"
}

Headers

You can set headers manually or through middlewares

app.get('/test', (req, res) => {
    res.header('Authorization', 'test');
    return httpResponses(res).body({body: {nested: "content"}}).message('Information').created();
});

Methods

Setting a body

httpResponses(res).body({test: 'body'});

Setting a message

httpResponses(res).message('This is an example.');

Codes 2xx

MethodDefault message response
successnone
creatednone
acceptednone
noContentnone

Codes 3xx

MethodDefault message response
multipleChoicesnone
movedPermanentlynone
foundnone
seeOthernone

Codes 4xx

MethodDefault message response
badRequestnone
unauthorizedYou are not authorized to access this ressource.
forbiddenAccess is forbidden.
notFoundThis item was not found.
methodNotAllowedThis method is not allowed for this ressource.
proxyAuthRequiredA proxy authentication is required.
requestTimeoutThe client did not produce a request within the time that the server was prepared to wait.
conflictThere is a conflict on the requested ressource.
goneThis ressource is no longer available.
lengthRequiredContent length must be specified for this ressource.
teapotI am a teapot.
misdirectedThis server is not able to produce a response for the given request.
unprocessableThe request was well-formed but was unable to be followed due to semantic errors.
lockedThis ressource has been locked.
tooManyRequestsYou have sent too many requests in a given amount of time.

Codes 5xx

MethodDefault message response
internalErrorAn error occurred, try again later or report it to the developers team.
notImplementedThis ressource is not implemented.
serviceUnavailableThe service is not available at this time, try again later.
insufficientStorageUnable to store the representation needed for to complete the request.
loopDetectedA loop was detected and the request has been aborted.
2.2.0

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.13

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago