1.0.0 • Published 2 years ago

@kalkuz/express-respond-status v1.0.0

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

npm version

Express Respond Status

Express Respond Status is a middleware for Express that adds response methods using the response object. This method allows you to easily send a response with a status code and a JSON body. It provides explanatory method names for each status code.

Installation

You can install this package using npm:

npm install @kalkuz/express-respond-status

Using yarn:

yarn add @kalkuz/express-respond-status

Dependencies

Express Respond Status only depends on Express.

Usage

Importing The Package

import Respond from '@kalkuz/express-respond-status';

Responding Requests

Example success responses:

// HTTP 200
Respond.OK(res, { somedata: 'somevalue' }, 'Any response message here');
// HTTP 201
Respond.Created(res, { somedata: 'somevalue' }, 'Any response message here');
// HTTP 202
Respond.Accepted(res, { somedata: 'somevalue' }, 'Any response message here');

Example error responses:

// HTTP 400
Respond.BadRequest(res,  { somedata: 'somevalue' }, 'Any response message here');
// HTTP 401
Respond.Unauthorized(res,  { somedata: 'somevalue' }, 'Any response message here');
// HTTP 403
Respond.Forbidden(res,  { somedata: 'somevalue' }, 'Any response message here');

Notes

  • The data parameter is optional. If you don't want to send any data, you can pass null or undefined as the second parameter.

  • The message parameter is optional. If you don't want to send any message, you can pass null or undefined as the third parameter.

Available Methods

HTTP Status CodeMethod Usage
100Continue(res, data, message)
101SwitchingProtocols(res, data, message)
102Processing(res, data, message)
103EarlyHints(res, data, message)
200OK(res, data, message)
201Created(res, data, message)
202Accepted(res, data, message)
203NonAuthoritativeInformation(res, data, message)
204NoContent(res, data, message)
205ResetContent(res, data, message)
206PartialContent(res, data, message)
207MultiStatus(res, data, message)
208AlreadyReported(res, data, message)
226IMUsed(res, data, message)
300MultipleChoices(res, data, message)
301MovedPermanently(res, data, message)
302Found(res, data, message)
303SeeOther(res, data, message)
304NotModified(res, data, message)
305UseProxy(res, data, message)
306Unused(res, data, message)
307TemporaryRedirect(res, data, message)
308PermanentRedirect(res, data, message)
400BadRequest(res, data, message)
401Unauthorized(res, data, message)
402PaymentRequired(res, data, message)
403Forbidden(res, data, message)
404NotFound(res, data, message)
405MethodNotAllowed(res, data, message)
406NotAcceptable(res, data, message)
407ProxyAuthenticationRequired(res, data, message)
408RequestTimeout(res, data, message)
409Conflict(res, data, message)
410Gone(res, data, message)
411LengthRequired(res, data, message)
412PreconditionFailed(res, data, message)
413PayloadTooLarge(res, data, message)
414URITooLong(res, data, message)
415UnsupportedMediaType(res, data, message)
416RangeNotSatisfiable(res, data, message)
417ExpectationFailed(res, data, message)
418ImATeapot(res, data, message)
421MisdirectRequest(res, data, message)
422UnprocessableEntity(res, data, message)
423Locked(res, data, message)
424FailedDependency(res, data, message)
425TooEarly(res, data, message)
426UpgradeRequired(res, data, message)
428PreconditionRequired(res, data, message)
429TooManyRequests(res, data, message)
431RequestHeaderFieldsTooLarge(res, data, message)
451UnavailableForLegalReasons(res, data, message)
500InternalServerError(res, data, message)
501NotImplemented(res, data, message)
502BadGateway(res, data, message)
503ServiceUnavailable(res, data, message)
504GatewayTimeout(res, data, message)
505HTTPVersionNotSupported(res, data, message)
506VariantAlsoNegotiates(res, data, message)
507InsufficientStorage(res, data, message)
508LoopDetected(res, data, message)
510NotExtended(res, data, message)
511NetworkAuthenticationRequired(res, data, message)

License

MIT License

1.0.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago