http-tag-string

0.1.1 • Public • Published

HTTP tagged strings

Describe processable HTTP requests using tagged strings.

License

MIT

Installation

npm i -S http-tag-string

Examples

Provide a full HTTP request message:

const HTTP = require( "http-tag-string" )( "http://example.com" );
 
HTTP`POST /some/url
Content-Type: application/json
 
{"info":"here it is..."}`()
    .then( response => {
        // handle the response ...
        return response.json();
    } )
    .then( json => {
        // process the returned JSON object ...
    } );

Provide the payload separately:

const HTTP = require( "http-tag-string" )( "http://example.com" );
 
const data = {
    info: "here it is...",
};
 
HTTP`POST /some/url
Content-Type: application/json`( data )
    .then( response => {
        // handle the response ...
        return response.json();
    } )
    .then( plainText => {
        // process some returned plain text string ...
    } );

Provide the payload as a readable stream:

const File = require( "fs" );
const HTTP = require( "http-tag-string" )( "http://example.com" );
 
HTTP`POST /some/url
Content-Type: application/json`( File.createReadStream( "/some/file.json" ) )
    .then( response => {
        // handle the response ...
        return response.content();
    } )
    .then( buffer => {
        // process some returned raw body Buffer ...
    } );

Readme

Keywords

Package Sidebar

Install

npm i http-tag-string

Weekly Downloads

4

Version

0.1.1

License

MIT

Unpacked Size

12.3 kB

Total Files

3

Last publish

Collaborators

  • soletan