Wreck 7.0.0 typings

This commit is contained in:
Marcin Porebski
2015-11-27 13:44:42 +01:00
parent fb2b3b1e06
commit 0dd5ad7c0f
2 changed files with 86 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
/// <reference path="wreck.d.ts" />
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);
+45
View File
@@ -0,0 +1,45 @@
// Type definitions for wreck 7.0.0
// Project: https://github.com/hapijs/wreck
// Definitions by: Marcin Porębski <http://github.com/marcinporebski>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
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;
}