Bomret / funkster-http-headers-accept

Adds combinators for parsing the HTTP Accept-* request headers in Funkster.
0 stars 0 forks source link

funkster-http-headers-accept

npm node npm Travis

Icon

Funkster is a compositional server library. This package contains combinators and types to parse the HTTP Accept* headers of a request.

Additional examples of how to build HTTP server apis with funkster can be found here.

Typscript is used to illustrate the examples.

Install

$ npm install funkster-http-headers-accept

Build

$ npm install && npm run build

Test

$ npm run test

Parsing the Accept* headers from a request

This module uses the accepts package so essentially the same api applies for the parsed headers object.

import * as http from 'http';
import { parseAcceptHeaders } from 'funkster-http-headers-accept';
import { asRequestListener, Ok } from 'funkster-http';

const pipe = parseAcceptHeaders(headers => Ok(headers.type('json')));
const server = http.createServer(asRequestListener(pipe));

// start the node HTTP server and send e.g. a GET with the Accept header set to 'application/json'.

Meta

Icon funky by iconsmind.com from the Noun Project.