0.1.1 • Published 5 years ago

http-tag-string v0.1.1

Weekly downloads
17
License
MIT
Repository
github
Last release
5 years ago

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 ...
	} );
0.1.1

5 years ago

0.1.0

5 years ago

0.0.3

5 years ago

0.0.2

6 years ago

0.0.1

6 years ago