Socket
Socket
Sign inDemoInstall

@haensl/http

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @haensl/http

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


Version published
Weekly downloads
12
decreased by-57.14%
Maintainers
1
Install size
6.13 kB
Created
Weekly downloads
 

Changelog

Source

1.1.1

  • #6: Update dependencies.

Readme

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

Last updated on 11 Mar 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc