http-types
Library for JSON serialisation of HTTP exchanges
Last updated 4 months ago by kimmo-meeshkan .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install http-types 
SYNC missed versions from official npm registry.

HTTP Types in TypeScript

Build Status MIT licensed npm version

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");
});

Current Tags

  • 0.6.1                                ...           latest (4 months ago)

7 Versions

  • 0.6.1                                ...           4 months ago
  • 0.6.0                                ...           5 months ago
  • 0.5.0                                ...           5 months ago
  • 0.4.0                                ...           5 months ago
  • 0.3.0                                ...           5 months ago
  • 0.2.0                                ...           5 months ago
  • 0.1.0                                ...           5 months ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (12)

Copyright 2014 - 2016 © taobao.org |