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

http-types

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-types

Library for JSON serialisation of HTTP exchanges

  • 0.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-60%
Maintainers
1
Weekly downloads
 
Created
Source

ts-http-types

Build Status MIT licensed

Typescript library to read and write records of HTTP exchanges in the HTTP types format.

Install

$ npm install http-types

Writing HTTP exchanges

Using HttpExchangeWriter a recording of HTTP traffic can be serialised for use with any program that can handle the HTTP Types format.

const writer = new HttpExchangeWriter();

const request = HttpRequestBuilder.fromPath({
  timestamp: timestamp,
  method: HttpMethod.GET,
  protocol: HttpProtocol.HTTPS,
  host: "example.com",
  headers: {
    "accept-encoding": "gzip, deflate, br",
    "cache-control": ["no-cache", "no-store"]
  },
  path: "/my/path?a=b&q=1&q=2",
  body: "request string body"
});

const response = HttpResponseBuilder.from({
  headers: {
    "accept-encoding": "gzip, deflate, br",
    "cache-control": "no-cache"
  },
  statusCode: 404,
  body: "response string body"
});

writer.write({ request, response });

// [...] (write multiple exchanges)

// writer.buffer contains the exchanges in the HTTP types JSON Lines format.
console.log(writer.buffer);

A HTTP request can also be created from query parameters as an object. The below request is identical to the one created above:

const request = HttpRequestBuilder.fromPathnameAndQuery({
  timestamp: timestamp,
  method: HttpMethod.GET,
  protocol: HttpProtocol.HTTPS,
  host: "example.com",
  headers: {
    "accept-encoding": "gzip, deflate, br",
    "cache-control": ["no-cache", "no-store"]
  },
  pathname: "/my/path",
  query: {
    a: "b",
    q: ["1", "2"]
  },
  body: "request string body"
});

Reading HTTP exchanges

With HttpExchangeReader HTTP Types recordings can be read for processing:

HttpExchangeReader.fromJsonLines(writer.buffer, exchange => {
  expect(exchange.request.host).toBe("example.com");
  expect(exchange.request.query.get("a")).toEqual("b");
});

Keywords

FAQs

Package last updated on 05 Feb 2020

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