Merge pull request #6967 from marcinporebski/master

Wreck 7.0.0
This commit is contained in:
Masahiro Wakame
2015-12-01 23:57:11 +09:00
2 changed files with 80 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
/// <reference path="wreck.d.ts" />
import Wreck = require('wreck');
Wreck.get('https://google.com/', {}, function (err: any, res: any, payload: any) {
/* 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
};
var optionalCallback = function (err: any, res: any) {
/* handle err if it exists, in which case res will be undefined */
// buffer the response stream
Wreck.read(res, null, function (err: any, body: any) {
/* do stuff */
});
};
var req = wreck.request(method, uri, options, optionalCallback);
+41
View File
@@ -0,0 +1,41 @@
// 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 WreckObject
{
defaults: (options: any) => WreckObject;
request: (method: string, uri: string, options: any, callback?: (err: any, response: http.IncomingMessage) => void) => http.ClientRequest;
read: (response: http.IncomingMessage, options: any, callback: (err: any, payload: any) => void) => void;
get: (uri: string, options: any, callback: (err: any, response: http.IncomingMessage, payload: any) => void) => http.ClientRequest;
post: (uri: string, options: any, callback: (err: any, response: http.IncomingMessage, payload: any) => void) => http.ClientRequest;
patch: (uri: string, options: any, callback: (err: any, response: http.IncomingMessage, payload: any) => void) => http.ClientRequest;
put: (uri: string, options: any, callback: (err: any, response: http.IncomingMessage, payload: any) => void) => http.ClientRequest;
delete: (uri: string, options: any, callback: (err: any, response: http.IncomingMessage, payload: any) => void) => http.ClientRequest;
toReadableStream: (payload: any, encoding?: string) => stream.Readable;
parseCacheControl: (field: string) => any;
agents: {
http: http.Agent,
https: http.Agent
};
}
var wreck: WreckObject;
export = wreck;
}