diff --git a/wreck/wreck-tests.ts b/wreck/wreck-tests.ts new file mode 100644 index 000000000..b1e8b0d0b --- /dev/null +++ b/wreck/wreck-tests.ts @@ -0,0 +1,41 @@ +/// + +import Wreck = require('wreck'); + +Wreck.get('https://google.com/', function (err, res, payload) { + /* do stuff */ +}); + + +var method = 'GET'; // GET, POST, PUT, DELETE +var uri = 'https://google.com/'; +var readableStream = Wreck.toReadableStream('foo=bar'); + +var wreck = Wreck.defaults({ + headers: { 'x-foo-bar': 123 } +}); + +// cascading example -- does not alter `wreck` +var wreckWithTimeout = wreck.defaults({ + timeout: 5 +}); + +// all attributes are optional +var options = { + maxBytes: 1048576, // 1 MB, default: unlimited + rejectUnauthorized: true, + downstreamRes: null, + agent: null, // Node Core http.Agent +}; + +var optionalCallback = function (err, res) { + + /* handle err if it exists, in which case res will be undefined */ + + // buffer the response stream + Wreck.read(res, null, function (err, body) { + /* do stuff */ + }); +}; + +var req = wreck.request(method, uri, options, optionalCallback); diff --git a/wreck/wreck.d.ts b/wreck/wreck.d.ts new file mode 100644 index 000000000..7198de2bb --- /dev/null +++ b/wreck/wreck.d.ts @@ -0,0 +1,45 @@ +// Type definitions for wreck 7.0.0 +// Project: https://github.com/hapijs/wreck +// Definitions by: Marcin Porębski +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module Wreck +{ + import http = require('http'); + import stream = require('stream'); + + + interface IWreckObject + { + defaults: (options: any) => IWreckObject; + + request: (method: string, uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage) => void = null) => http.ClientRequest; + + read: (response: http.IncomingMessage, options: any, callback: (err: any, payload: any) => void) => void; + + get: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; + post: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; + patch: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; + put: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; + delete: (uri: string, options: any = null, callback: (err: any, response: http.IncomingMessage, payload: any) => void = null) => http.ClientRequest; + + toReadableStream: (payload: any, encoding: string = null) => stream.Readable; + + parseCacheControl: (field: string) => any; + + agents: { + http: http.Agent, + https: http.Agent + }; + } + +} + +declare module "wreck" +{ + var wreck: Wreck.IWreckObject; + + export = wreck; +}