1.0.0 • Published 5 years ago

http-status-codes-responses v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

HTTP Status Codes Responses Coverage Status license

Don't spend time writing personalized response body for non-success requests.

How to use?

  1. Install lib
npm install http-status-codes-responses
  1. Use it
const {ok, notFound} = require('http-status-codes-responses');

const person = new Person();
let john = person.findOne(1);
const ctx = (john !== undefined) ? ok({}, john.json()) : notFound({});

If John exists, the result will be as following with status code 200:

{
    "name": "John",
    "occupation": "singer",
}

Otherwise the HTTP response status code will setted to 404 with body:

{
    "message": "Not Found"
}

Implemented Status Code

FunctionStatus CodeDefault Message
accepted202{ message: 'Accepted' }
badGateway502{ message: 'Bad Gateway' }
badRequest400{ message: 'Bad Request' }
conflict409{ message: 'Conflict' }
continue100{ message: 'Continue' }
created201{ message: 'Created' }
expectationFailed417{ message: 'Expectation Failed' }
failedDependency424{ message: 'Failed Dependency' }
forbidden403{ message: 'Forbidden' }
gatewayTimeout504{ message: 'Gateway Timeout' }
gone410{ message: 'Gone' }
httpVersionNotSupported505{ message: 'HTTP Version Not Supported' }
imATeapot418{ message: 'I\'m a teapot' }
insufficientSpaceOnResource419{ message: 'Insufficient Space on Resource' }
insufficientStorage507{ message: 'Insufficient Storage' }
internalServerError500{ message: 'Server Error' }
lengthRequired411{ message: 'Length Required' }
locked423{ message: 'Locked' }
methodFailure420{ message: 'Method Failure' }
methodNotAllowed405{ message: 'Method Not Allowed' }
movedPermanently301{ message: 'Moved Permanently' }
movedTemporarily302{ message: 'Moved Temporarily' }
multiStatus207{ message: 'Multi-Status' }
multipleChoices300{ message: 'Multiple Choices' }
networkAuthenticationRequired511{ message: 'Network Authentication Required' }
noContent204{ message: 'No Content' }
nonAuthoritativeInformation203{ message: 'Non Authoritative Information' }
notAcceptable406{ message: 'Not Acceptable' }
notFound404{ message: 'Not Found' }
notImplemented501{ message: 'Not Implemented' }
notModified304{ message: 'Not Modified' }
ok200{ message: 'OK' }
partialContent206{ message: 'Partial Content' }
paymentRequired402{ message: 'Payment Required' }
permanentRedirect308{ message: 'Permanent Redirect' }
preconditionFailed412{ message: 'Precondition Failed' }
preconditionRequired428{ message: 'Precondition Required' }
processing102{ message: 'Processing' }
proxyAuthenticationRequired407{ message: 'Proxy Authentication Required' }
requestHeaderFieldsTooLarge431{ message: 'Request Header Fields Too Large' }
requestTimeout408{ message: 'Request Timeout' }
requestTooLong413{ message: 'Request Entity Too Large' }
requestUriTooLong414{ message: 'Request-URI Too Long' }
requestedRangeNotSatisfiable416{ message: 'Requested Range Not Satisfiable' }
resetContent205{ message: 'Reset Content' }
seeOther303{ message: 'See Other' }
serviceUnavailable503{ message: 'Service Unavailable' }
switchingProtocols101{ message: 'Switching Protocols' }
temporaryRedirect307{ message: 'Temporary Redirect' }
tooManyRequests429{ message: 'Too Many Requests' }
unauthorized401{ message: 'Unauthorized' }
unprocessableEntity422{ message: 'Unprocessable Entity' }
unsupportedMediaType415{ message: 'Unsupported Media Type' }
useProxy305{ message: 'Use Proxy' }

Tests

npm test