npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-standard-http-responses

v2.2.0

Published

Helper package used to manage http responses for express

Downloads

4

Readme

Foreword

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

Installation

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

Environment used

[email protected]
[email protected]

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

| Method | Default message response | |-----------|--------------------------| | success | none | | created | none | | accepted | none | | noContent | none |

Codes 3xx

| Method | Default message response | |------------------|--------------------------| | multipleChoices | none | | movedPermanently | none | | found | none | | seeOther | none |

Codes 4xx

| Method | Default message response | |-------------------|----------------------------------------------------------------------------------------------| | badRequest | none | | unauthorized | You are not authorized to access this ressource. | | forbidden | Access is forbidden. | | notFound | This item was not found. | | methodNotAllowed | This method is not allowed for this ressource. | | proxyAuthRequired | A proxy authentication is required. | | requestTimeout | The client did not produce a request within the time that the server was prepared to wait. | | conflict | There is a conflict on the requested ressource. | | gone | This ressource is no longer available. | | lengthRequired | Content length must be specified for this ressource. | | teapot | I am a teapot. | | misdirected | This server is not able to produce a response for the given request. | | unprocessable | The request was well-formed but was unable to be followed due to semantic errors. | | locked | This ressource has been locked. | | tooManyRequests | You have sent too many requests in a given amount of time. |

Codes 5xx

| Method | Default message response | |---------------------|---------------------------------------------------------------------------| | internalError | An error occurred, try again later or report it to the developers team. | | notImplemented | This ressource is not implemented. | | serviceUnavailable | The service is not available at this time, try again later. | | insufficientStorage | Unable to store the representation needed for to complete the request. | | loopDetected | A loop was detected and the request has been aborted. |