Skip to content

cepharum/http-tag-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

supports tagged strings describing processable HTTP requests

Resources

Stars

Watchers

Forks

Packages

No packages published