1+ // Type definitions for fetch API
2+ // Project: https://github.com/github/fetch
3+ // Definitions by: Ryan Graham <https://github.com/ryan-codingintrigue>
4+ // Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+ /// <reference path="../es6-promise.d.ts" />
7+
8+ declare module "fetch" {
9+
10+ class Request {
11+ constructor ( input : string | Request , init ?: RequestInit ) ;
12+ method : string ;
13+ url : string ;
14+ headers : Headers ;
15+ context : RequestContext ;
16+ referrer : string ;
17+ mode : RequestMode ;
18+ credentials : RequestCredentials ;
19+ cache : RequestCache ;
20+ }
21+
22+ interface RequestInit {
23+ method ?: string ;
24+ headers ?: HeaderInit | { [ index : string ] : string } ;
25+ body ?: BodyInit ;
26+ mode ?: RequestMode ;
27+ credentials ?: RequestCredentials ;
28+ cache ?: RequestCache ;
29+ }
30+
31+ enum RequestContext {
32+ "audio" , "beacon" , "cspreport" , "download" , "embed" , "eventsource" , "favicon" , "fetch" ,
33+ "font" , "form" , "frame" , "hyperlink" , "iframe" , "image" , "imageset" , "import" ,
34+ "internal" , "location" , "manifest" , "object" , "ping" , "plugin" , "prefetch" , "script" ,
35+ "serviceworker" , "sharedworker" , "subresource" , "style" , "track" , "video" , "worker" ,
36+ "xmlhttprequest" , "xslt"
37+ }
38+
39+ enum RequestMode { "same-origin" , "no-cors" , "cors" }
40+ enum RequestCredentials { "omit" , "same-origin" , "include" }
41+ enum RequestCache { "default" , "no-store" , "reload" , "no-cache" , "force-cache" , "only-if-cached" }
42+
43+ class Headers {
44+ append ( name : string , value : string ) : void ;
45+ delete ( name : string ) : void ;
46+ get ( name : string ) : string ;
47+ getAll ( name : string ) : Array < string > ;
48+ has ( name : string ) : boolean ;
49+ set ( name : string , value : string ) : void ;
50+ }
51+
52+ class Body {
53+ bodyUsed : boolean ;
54+ arrayBuffer ( ) : Promise < ArrayBuffer > ;
55+ blob ( ) : Promise < Blob > ;
56+ formData ( ) : Promise < FormData > ;
57+ json ( ) : Promise < any > ;
58+ text ( ) : Promise < string > ;
59+ }
60+
61+ class Response extends Body {
62+ constructor ( body ?: BodyInit , init ?: ResponseInit ) ;
63+ error ( ) : Response ;
64+ redirect ( url : string , status : number ) : Response ;
65+ type : ResponseType ;
66+ url : string ;
67+ status : number ;
68+ ok : boolean ;
69+ statusText : string ;
70+ headers : Headers ;
71+ clone ( ) : Response ;
72+ }
73+
74+ enum ResponseType { "basic" , "cors" , "default" , "error" , "opaque" }
75+
76+ class ResponseInit {
77+ status : number ;
78+ statusText : string ;
79+ headers : HeaderInit ;
80+ }
81+
82+ type HeaderInit = Headers | Array < string > ;
83+ type BodyInit = Blob | FormData | string ;
84+ type RequestInfo = Request | string ;
85+
86+ function fetch ( url : string , init ?: RequestInit ) : Promise < Response > ;
87+ }
0 commit comments