import * as rm from 'typed-rest-client/RestClient' ; import * as fs from 'fs' ; import * as path from 'path' ; import * as cm from './common' ; let baseUrl = 'https://httpbin.org' ; let restc = new rm . RestClient ( 'rest-samples' , baseUrl ) ; export async function run ( ) { try { cm . banner ( 'Rest Samples' ) ; cm . heading ( 'get rest obj' ) ; let restRes = await restc . get < cm . HttpBinData > ( 'get' ) ; console . log ( restRes . statusCode , restRes . result [ 'url' ] ) ; interface HelloObj { message : string ; } let hello = < HelloObj > { message : "Hello World!" } ; let options = cm . httpBinOptions ( ) ; cm . heading ( 'create rest obj' ) ; let hres = await restc . create < HelloObj > ( '/post' , hello , options ) ; console . log ( hres . result ) ; cm . heading ( 'update rest obj' ) ; hello . message += '!' ; hres = await restc . update < HelloObj > ( 'https://httpbin.org/patch' , hello , options ) ; console . log ( hres . result ) ; cm . heading ( 'options rest call' ) ; let ores = await restc . options < void > ( '' , options ) ; console . log ( ores . statusCode ) ; } catch ( err ) { console . error ( 'Failed: ' + err . message ) ; } }