import http = require ( "http" ) ; import * as restm from 'typed-rest-client/RestClient' ; export interface HttpBinData { url : string ; data : any ; } export function getEnv ( name ) { let val = process . env [ name ] ; return val ; } export function banner ( title ) { console . log ( ) ; console . log ( '=======================================' ) ; console . log ( '\t' + title ) ; console . log ( '=======================================' ) ; } export function heading ( title ) { console . log ( ) ; console . log ( '> ' + title ) ; } export async function outputHttpBinResponse ( body , message ? ) { if ( message ) { if ( message . statusCode ) { console . log ( 'status' , message . statusCode ) ; } if ( message . rawHeaders ) { console . log ( 'headers:' + JSON . stringify ( message . rawHeaders ) ) ; } } if ( body ) { let obj = JSON . parse ( body . toString ( ) ) ; console . log ( 'response from ' + obj . url ) ; if ( obj . data ) { console . log ( 'data:' , obj . data ) ; } } } export function httpBinOptions ( ) { let options = < restm . IRequestOptions > { } ; options . responseProcessor = ( obj ) => { return obj [ 'data' ] ; } ; return options ; }