New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

http-request-builder

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-request-builder

Build HTTP request message from an object model

  • 2.0.0-alpha
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

http-request-builder

Build HTTP request message from an object model. Can be used on server and client sides. To parse request message and create an object model for it, use http-request-parser.

Build Status Code Coverage npm version

Features

  • Build HTTP request message:
    • headers (with parameters)
    • cookies
    • body (with supported contentTypes: multipart/form-data, application/x-www-form-urlencoded, text/plain)

Installation

$ npm i -S http-request-builder

Usage

const builder = require('http-request-builder');

let requestObj = { 
  method: 'GET',
  protocol: 'HTTP',
  url: 'example.com/features?p1=v1',
  protocolVersion: 'HTTP/1.1',
  host: 'example.com',
  headers: [ 
    { name: 'Connection', values: [ { value: 'keep-alive' } ] },
    { name: 'Cache-Control', values: [ { value: 'no-cache' } ] },
    { name: 'User-Agent', values: [ { value: 'Mozilla/5.0 (Windows NT 6.1 WOW64)' } ]},
    { name: 'Accept', values: [ { value: '*/*' } ] },
    { name: 'Accept-Encoding', values: [ 
      { value: 'gzip' },
      { value: 'deflate' }
    ]},
    { name: 'Accept-Language', values: [
      { value: 'en-US', params: 'q=0.6' },
      { value: 'en', params: 'q=0.4' } 
    ]}
  ],
  cookie: [
    { name: 'csrftoken', value: '123abc' },
    { name: 'sessionid', value: '456def' }
  ]
};

let requestMsg = builder.build(requestObj);
console.log(requestMsg);

/* prints:
GET http://app.com/features?p1=v1 HTTP/1.1
Host: app.com
Connection: keep-alive
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 6.1 WOW64)
Accept: /
Accept-Encoding: gzip, deflate
Accept-Language: en-US;q=0.6, en;q=0.4
Cookie: csrftoken=123abc; sessionid=456def


*/

Author

Alexander Mac

License

Licensed under the MIT license.

Keywords

FAQs

Package last updated on 18 Jan 2019

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