0.6.0 • Published 8 months ago

http-response-text v0.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

http-response-text

In-takes HTTP status code and language code (default to 'en'), spits out response object with corresponding human-readable text message.

Based on MDN web docs for HTTP response status codes.

Usage

Install this package with pnpm add http-response-text (or npm install http-response-text if you prefer), then just import the getStatus method and pass in the status code. For example, the following code snippet validates a user input object id for MongoDB and return an 404 response object for non-valid payload:

import { MongoClient, ObjectId } from "mongodb";
import { getStatus } from "http-response-text";

const findById = async (collectionName, id) => {
  // console.log("findById: ", collectionName, id);
  if (!ObjectId.isValid(id)) return getStatus(404) ?? null;

  // ...
};

Which would return you a response object like this:

{
  code: 404,
  message: 'Not Found'
}
0.6.0

8 months ago

0.5.0

9 months ago

0.4.0

9 months ago

0.3.0

9 months ago

0.2.2

9 months ago

0.2.1

9 months ago

0.2.0

9 months ago