Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@haensl/http

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@haensl/http

Simple JSON object of common HTTP headers, status codes and methods.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@haensl/http

Simple JSON support module bundling common HTTP headers, status codes and methods.

NPM

npm version CircleCI

Installation

Via npm

$ npm install -S @haensl/http

Via yarn

$ yarn add @haensl/http

Usage

  1. Install @haensl/http

  2. Use http status codes, methods and headers in your projects:

    ESM, i.e. import

    import { statusCodes} from '@haensl/http';
    
    // ...
    const response = await fetch(url);
    
    if (response.statusCode < statusCodes.badRequest) {
      // do stuff when response status code < 400
    }
    
    // ...
    

    CJS, i.e. require

    const { headers, methods } = require('@haensl/http');
    
    // ...
    const requestOptions = {
      headers: {
        [headers.contentType]: 'application/json'
      },
      method: methods.post,
      body: JSON.stringify(data)
    };
    
    const response = await fetch(url, requestOptions);
    
    // ...
    

Synopsis

The http object is a simple JSON object that maps status codes, headers and strings:

{
  "statusCodes": {
    "ok": 200,
    "created": 201,
    "accepted": 202,
    // ...
  },
  "headers": {
    "accept": "Accept",
    "accessControl": {
      "allow": {
        "origin": "Access-Control-Allow-Origin",
        "methods": "Access-Control-Allow-Methods"
        // ...
      },
      // ...
    },
    "authorization": "Authorization",
    "contentType": "Content-Type",
    // ...
  },
  "methods": {
    "delete": "delete",
    "get": "get",
    // ...
  }
}

JSON

Attention: This JSON object is not exhaustive(, yet)! If you need a status code, header or method added, please create a feature request

Changelog

Keywords

FAQs

Package last updated on 03 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc