mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 20:21:46 +00:00
Needle (#12108)
* Derive type of response in callback from nodes IncomingMessage * Allow any request header name
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
/// <reference path="needle.d.ts" />
|
||||
|
||||
import needle = require("needle");
|
||||
import * as needle from "needle";
|
||||
|
||||
function Usage() {
|
||||
// using callback
|
||||
needle.get('http://ifconfig.me/all.json', function (error, response) {
|
||||
if (!error)
|
||||
console.log(response.body.ip_addr); // JSON decoding magic. :)
|
||||
console.log(response.statusCode);
|
||||
});
|
||||
|
||||
// using streams
|
||||
@@ -15,7 +15,9 @@ function Usage() {
|
||||
}
|
||||
|
||||
function ResponsePipeline() {
|
||||
needle.get('http://stackoverflow.com/feeds', { compressed: true }, function (err, resp) {
|
||||
needle.get('http://stackoverflow.com/feeds', { compressed: true, headers: {
|
||||
Authorization: 'bearer 12dsfgsdgsgq'
|
||||
} }, function (err, resp) {
|
||||
console.log(resp.body); // this little guy won't be a Gzipped binary blob
|
||||
// but a nice object containing all the latest entries
|
||||
});
|
||||
|
||||
Vendored
+80
-88
@@ -5,95 +5,87 @@
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
declare namespace Needle {
|
||||
interface ReadableStream extends NodeJS.ReadableStream {
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
(error: Error, response: any, body: any): void;
|
||||
}
|
||||
|
||||
interface RequestOptions {
|
||||
timeout?: number;
|
||||
follow?: number;
|
||||
follow_max?: number;
|
||||
multipart?: boolean;
|
||||
proxy?: string;
|
||||
agent?: string;
|
||||
headers?: HttpHeaderOptions;
|
||||
auth?: string; // auto | digest | basic (default)
|
||||
json?: boolean;
|
||||
|
||||
// These properties are overwritten by those in the 'headers' field
|
||||
compressed?: boolean;
|
||||
cookies?: { [name: string]: any; };
|
||||
// Overwritten if present in the URI
|
||||
username?: string;
|
||||
password?: string;
|
||||
}
|
||||
|
||||
interface ResponseOptions {
|
||||
decode?: boolean;
|
||||
parse?: boolean;
|
||||
output?: any;
|
||||
}
|
||||
|
||||
interface HttpHeaderOptions {
|
||||
cookies?: { [name: string]: any; };
|
||||
compressed?: boolean;
|
||||
accept?: string;
|
||||
connection?: string;
|
||||
user_agent?: string;
|
||||
|
||||
// Overwritten if present in the URI
|
||||
username?: string;
|
||||
password?: string;
|
||||
}
|
||||
|
||||
interface TLSOptions {
|
||||
pfx?: any;
|
||||
key?: any;
|
||||
passphrase?: string;
|
||||
cert?: any;
|
||||
ca?: any;
|
||||
ciphers?: any;
|
||||
rejectUnauthorized?: boolean;
|
||||
secureProtocol?: any;
|
||||
}
|
||||
|
||||
interface NeedleOptions extends RequestOptions, ResponseOptions, HttpHeaderOptions, TLSOptions {
|
||||
}
|
||||
|
||||
interface NeedleStatic {
|
||||
defaults(options?: any): void;
|
||||
|
||||
head(url: string): ReadableStream;
|
||||
head(url: string, callback?: Callback): ReadableStream;
|
||||
head(url: string, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
get(url: string): ReadableStream;
|
||||
get(url: string, callback?: Callback): ReadableStream;
|
||||
get(url: string, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
post(url: string, data: any): ReadableStream;
|
||||
post(url: string, data: any, callback?: Callback): ReadableStream;
|
||||
post(url: string, data: any, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
put(url: string, data: any): ReadableStream;
|
||||
put(url: string, data: any, callback?: Callback): ReadableStream;
|
||||
put(url: string, data: any, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
delete(url: string, data: any): ReadableStream;
|
||||
delete(url: string, data: any, callback?: Callback): ReadableStream;
|
||||
delete(url: string, data: any, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
request(method: string, url: string, data: any): ReadableStream;
|
||||
request(method: string, url: string, data: any, callback?: Callback): ReadableStream;
|
||||
request(method: string, url: string, data: any, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "needle" {
|
||||
import * as http from 'http';
|
||||
import * as Buffer from 'buffer';
|
||||
module Needle {
|
||||
interface NeedleResponse extends http.IncomingMessage {
|
||||
body: any;
|
||||
raw: Buffer;
|
||||
bytes: number;
|
||||
}
|
||||
interface ReadableStream extends NodeJS.ReadableStream {
|
||||
}
|
||||
|
||||
interface Callback {
|
||||
(error: Error, response: NeedleResponse, body: any): void;
|
||||
}
|
||||
|
||||
interface RequestOptions {
|
||||
timeout?: number;
|
||||
follow?: number;
|
||||
follow_max?: number;
|
||||
multipart?: boolean;
|
||||
proxy?: string;
|
||||
agent?: string;
|
||||
headers?: Object;
|
||||
auth?: string; // auto | digest | basic (default)
|
||||
json?: boolean;
|
||||
|
||||
// These properties are overwritten by those in the 'headers' field
|
||||
compressed?: boolean;
|
||||
cookies?: { [name: string]: any; };
|
||||
// Overwritten if present in the URI
|
||||
username?: string;
|
||||
password?: string;
|
||||
}
|
||||
|
||||
interface ResponseOptions {
|
||||
decode?: boolean;
|
||||
parse?: boolean;
|
||||
output?: any;
|
||||
}
|
||||
|
||||
interface TLSOptions {
|
||||
pfx?: any;
|
||||
key?: any;
|
||||
passphrase?: string;
|
||||
cert?: any;
|
||||
ca?: any;
|
||||
ciphers?: any;
|
||||
rejectUnauthorized?: boolean;
|
||||
secureProtocol?: any;
|
||||
}
|
||||
|
||||
interface NeedleStatic {
|
||||
defaults(options?: any): void;
|
||||
|
||||
head(url: string): ReadableStream;
|
||||
head(url: string, callback?: Callback): ReadableStream;
|
||||
head(url: string, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
get(url: string): ReadableStream;
|
||||
get(url: string, callback?: Callback): ReadableStream;
|
||||
get(url: string, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
post(url: string, data: any): ReadableStream;
|
||||
post(url: string, data: any, callback?: Callback): ReadableStream;
|
||||
post(url: string, data: any, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
put(url: string, data: any): ReadableStream;
|
||||
put(url: string, data: any, callback?: Callback): ReadableStream;
|
||||
put(url: string, data: any, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
delete(url: string, data: any): ReadableStream;
|
||||
delete(url: string, data: any, callback?: Callback): ReadableStream;
|
||||
delete(url: string, data: any, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
|
||||
request(method: string, url: string, data: any): ReadableStream;
|
||||
request(method: string, url: string, data: any, callback?: Callback): ReadableStream;
|
||||
request(method: string, url: string, data: any, options?: RequestOptions, callback?: Callback): ReadableStream;
|
||||
}
|
||||
}
|
||||
|
||||
var needle: Needle.NeedleStatic;
|
||||
export = needle;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user