package js_of_ocaml

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file fetch.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
(* Js_of_ocaml library
 * http://www.ocsigen.org/js_of_ocaml/
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, with linking exception;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *)

open! Import

class type headers = object
  method append : Js.js_string Js.t -> Js.js_string Js.t -> unit Js.meth

  method delete : Js.js_string Js.t -> unit Js.meth

  method get : Js.js_string Js.t -> Js.js_string Js.t Js.opt Js.meth

  method has : Js.js_string Js.t -> bool Js.t Js.meth

  method set : Js.js_string Js.t -> Js.js_string Js.t -> unit Js.meth

  method forEach :
       (Js.js_string Js.t -> Js.js_string Js.t -> headers Js.t -> unit) Js.callback
    -> unit Js.meth
end

let headers : headers Js.t Js.constr = Js.Unsafe.global##._Headers

let headers_of_list (l : (string * string) list) : headers Js.t =
  let h = new%js headers in
  List.iter (fun (k, v) -> h##append (Js.string k) (Js.string v)) l;
  h

class type body = object
  method bodyUsed : bool Js.t Js.readonly_prop

  method arrayBuffer : Typed_array.arrayBuffer Js.t Promise.t Js.meth

  method blob : File.blob Js.t Promise.t Js.meth

  method json : Js.Unsafe.any Promise.t Js.meth

  method text : Js.js_string Js.t Promise.t Js.meth

  method formData : Form.formData Js.t Promise.t Js.meth
end

class type requestInit = object
  method _method : Js.js_string Js.t Js.writeonly_prop

  method headers : headers Js.t Js.writeonly_prop

  method body : Js.Unsafe.any Js.writeonly_prop

  method mode : Js.js_string Js.t Js.writeonly_prop

  method credentials : Js.js_string Js.t Js.writeonly_prop

  method cache : Js.js_string Js.t Js.writeonly_prop

  method redirect : Js.js_string Js.t Js.writeonly_prop

  method referrer : Js.js_string Js.t Js.writeonly_prop

  method referrerPolicy : Js.js_string Js.t Js.writeonly_prop

  method integrity : Js.js_string Js.t Js.writeonly_prop

  method keepalive : bool Js.t Js.writeonly_prop

  method signal : Abort.signal Js.t Js.writeonly_prop
end

let empty_request_init () : requestInit Js.t = Js.Unsafe.obj [||]

class type request = object
  inherit body

  method url : Js.js_string Js.t Js.readonly_prop

  method _method : Js.js_string Js.t Js.readonly_prop

  method headers : headers Js.t Js.readonly_prop

  method destination : Js.js_string Js.t Js.readonly_prop

  method referrer : Js.js_string Js.t Js.readonly_prop

  method referrerPolicy : Js.js_string Js.t Js.readonly_prop

  method mode : Js.js_string Js.t Js.readonly_prop

  method credentials : Js.js_string Js.t Js.readonly_prop

  method cache : Js.js_string Js.t Js.readonly_prop

  method redirect : Js.js_string Js.t Js.readonly_prop

  method integrity : Js.js_string Js.t Js.readonly_prop

  method keepalive : bool Js.t Js.readonly_prop

  method signal : Abort.signal Js.t Js.readonly_prop

  method clone : request Js.t Js.meth
end

let request : (Js.js_string Js.t -> request Js.t) Js.constr = Js.Unsafe.global##._Request

let request_with_init : (Js.js_string Js.t -> requestInit Js.t -> request Js.t) Js.constr
    =
  Js.Unsafe.global##._Request

let request_of_request : (request Js.t -> request Js.t) Js.constr =
  Js.Unsafe.global##._Request

let request_of_request_with_init :
    (request Js.t -> requestInit Js.t -> request Js.t) Js.constr =
  Js.Unsafe.global##._Request

class type responseInit = object
  method status : int Js.writeonly_prop

  method statusText : Js.js_string Js.t Js.writeonly_prop

  method headers : headers Js.t Js.writeonly_prop
end

let empty_response_init () : responseInit Js.t = Js.Unsafe.obj [||]

class type response = object
  inherit body

  method headers : headers Js.t Js.readonly_prop

  method ok : bool Js.t Js.readonly_prop

  method redirected : bool Js.t Js.readonly_prop

  method status : int Js.readonly_prop

  method statusText : Js.js_string Js.t Js.readonly_prop

  method _type : Js.js_string Js.t Js.readonly_prop

  method url : Js.js_string Js.t Js.readonly_prop

  method clone : response Js.t Js.meth
end

let response : (Js.Unsafe.any -> response Js.t) Js.constr = Js.Unsafe.global##._Response

let response_with_init : (Js.Unsafe.any -> responseInit Js.t -> response Js.t) Js.constr =
  Js.Unsafe.global##._Response

let fetch_global = Js.Unsafe.global##.fetch

let is_supported () = Js.Optdef.test fetch_global

let fetch (url : Js.js_string Js.t) : response Js.t Promise.t =
  Promise.of_any (Js.Unsafe.fun_call fetch_global [| Js.Unsafe.inject url |])

let fetch_with_init (url : Js.js_string Js.t) (init : requestInit Js.t) :
    response Js.t Promise.t =
  Promise.of_any
    (Js.Unsafe.fun_call fetch_global [| Js.Unsafe.inject url; Js.Unsafe.inject init |])

let fetch_request (req : request Js.t) : response Js.t Promise.t =
  Promise.of_any (Js.Unsafe.fun_call fetch_global [| Js.Unsafe.inject req |])