@kalkuz/express-respond-status
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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

License

MIT License

Readme

Keywords

none

Package Sidebar

Install

npm i @kalkuz/express-respond-status

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

232 kB

Total Files

20

Last publish

Collaborators

  • oguzhankalkuz