forked from reasonml-community/bs-express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Express.rei
423 lines (375 loc) · 12.8 KB
/
Express.rei
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
type complete;
/** abstract type which ensure middleware function must either
call the [next] function or one of the [send] function on the
response object.
This should be a great argument for OCaml, the type system
prevents silly error which in this case would make the server hang */
module Error: {
type t = exn;
/** Error type */
let message: Js_exn.t => option(string);
let name: Js_exn.t => option(string);
};
module Request: {
type t;
type params = Js.Dict.t(Js.Json.t);
/** [params request] return the JSON object filled with the
request parameters */
let params: t => params;
/** [asJsonObject request] casts a [request] to a JSON object. It is
common in Express application to use the Request object as a
placeholder to maintain state through the various middleware which
are executed. */
let asJsonObject: t => Js.Dict.t(Js.Json.t);
/** [baseUrl request] returns the 'baseUrl' property */
let baseUrl: t => string;
/** When using the json body-parser middleware and receiving a request with a
content type of "application/json", this property is a Js.Json.t that
contains the body sent by the request. */
let bodyJSON: t => option(Js.Json.t);
/** When using the raw body-parser middleware and receiving a request with a
content type of "application/octet-stream", this property is a
Node_buffer.t that contains the body sent by the request. */
let bodyRaw: t => option(Node_buffer.t);
/** When using the text body-parser middleware and receiving a request with a
content type of "text/plain", this property is a string that
contains the body sent by the request. */
let bodyText: t => option(string);
/** When using the urlencoded body-parser middleware and receiving a request
with a content type of "application/x-www-form-urlencoded", this property
is a Js.Dict.t string that contains the body sent by the request. */
let bodyURLEncoded: t => option(Js.Dict.t(string));
/** When using cookie-parser middleware, this property is an object
that contains cookies sent by the request. If the request contains
no cookies, it defaults to {}.*/
let cookies: t => option(Js.Dict.t(Js.Json.t));
/** When using cookie-parser middleware, this property contains signed cookies
sent by the request, unsigned and ready for use. Signed cookies reside in
a different object to show developer intent; otherwise, a malicious attack
could be placed on req.cookie values (which are easy to spoof).
Note that signing a cookie does not make it “hidden” or encrypted;
but simply prevents tampering (because the secret used to
sign is private). */
let signedCookies: t => option(Js.Dict.t(Js.Json.t));
/** [hostname request] Contains the hostname derived from the Host
HTTP header. */
let hostname: t => string;
/** [ip request] Contains the remote IP address of the request. */
let ip: t => string;
/** [fresh request] returns [true] whether the request is "fresh" */
let fresh: t => bool;
/** [stale request] returns [true] whether the request is "stale" */
let stale: t => bool;
/** [method_ request] return a string corresponding to the HTTP
method of the request: GET, POST, PUT, and so on */
let methodRaw: t => string;
type httpMethod =
| Get
| Post
| Put
| Delete
| Head
| Options
| Trace
| Connect
| Patch;
/** [method_ request] return a variant corresponding to the HTTP
method of the request: Get, Post, Put, and so on */
let httpMethod: t => httpMethod;
/** [originalUrl request] returns the original url. See
https://expressjs.com/en/4x/api.html#req.originalUrl */
let originalUrl: t => string;
/** [path request] returns the path part of the request URL. */
let path: t => string;
type protocol =
| Http
| Https;
/** [protocol request] returns the request protocol string: either http
or (for TLS requests) https. */
let protocol: t => protocol;
/** [secure request] returns [true] if a TLS connection is established */
let secure: t => bool;
/** [query request] returns an object containing a property for each
query string parameter in the route. If there is no query string,
it returns the empty object, {} */
let query: t => Js.Dict.t(Js.Json.t);
/** [acceptsRaw accepts types] checks if the specified content types
are acceptable, based on the request's Accept HTTP header field.
The method returns the best match, or if none of the specified
content types is acceptable, returns [false] */
let accepts: (array(string), t) => option(string);
let acceptsCharsets: (array(string), t) => option(string);
/** [get return field] returns the specified HTTP request header
field (case-insensitive match) */
let get: (string, t) => option(string);
/** [xhr request] returns [true] if the request’s X-Requested-With
header field is "XMLHttpRequest", indicating that the request was
issued by a client library such as jQuery */
let xhr: t => bool;
};
module Response: {
type t;
module StatusCode: {
type t =
| Ok
| Created
| Accepted
| NonAuthoritativeInformation
| NoContent
| ResetContent
| PartialContent
| MultiStatus
| AleadyReported
| IMUsed
| MultipleChoices
| MovedPermanently
| Found
| SeeOther
| NotModified
| UseProxy
| SwitchProxy
| TemporaryRedirect
| PermanentRedirect
| BadRequest
| Unauthorized
| PaymentRequired
| Forbidden
| NotFound
| MethodNotAllowed
| NotAcceptable
| ProxyAuthenticationRequired
| RequestTimeout
| Conflict
| Gone
| LengthRequired
| PreconditionFailed
| PayloadTooLarge
| UriTooLong
| UnsupportedMediaType
| RangeNotSatisfiable
| ExpectationFailed
| ImATeapot
| MisdirectedRequest
| UnprocessableEntity
| Locked
| FailedDependency
| UpgradeRequired
| PreconditionRequired
| TooManyRequests
| RequestHeaderFieldsTooLarge
| UnavailableForLegalReasons
| InternalServerError
| NotImplemented
| BadGateway
| ServiceUnavailable
| GatewayTimeout
| HttpVersionNotSupported
| VariantAlsoNegotiates
| InsufficientStorage
| LoopDetected
| NotExtended
| NetworkAuthenticationRequired;
let fromInt: int => option(t);
let toInt: t => int;
};
let sendFile: (string, 'a, t) => complete;
let sendString: (string, t) => complete;
let sendJson: (Js.Json.t, t) => complete;
let sendBuffer: (Node.Buffer.t, t) => complete;
let sendArray: (array('a), t) => complete;
let sendRawStatus: (int, t) => complete;
let sendStatus: (StatusCode.t, t) => complete;
let rawStatus: (int, t) => t;
let status: (StatusCode.t, t) => t;
let cookie:
(
~name: string,
~maxAge: int=?,
~expiresGMT: Js.Date.t=?,
~httpOnly: bool=?,
~secure: bool=?,
~signed: bool=?,
~path: string=?,
~sameSite: [ | `Lax | `Strict]=?,
~domain: string=?,
Js.Json.t,
t
) =>
t;
/**
Web browsers and other compliant clients will only clear the cookie if the given options is identical to those given to res.cookie(), excluding expires and maxAge.
*/
let clearCookie:
(
~name: string,
~httpOnly: bool=?,
~secure: bool=?,
~signed: bool=?,
~path: string=?,
~sameSite: [ | `Lax | `Strict]=?,
t
) =>
t;
let json: (Js.Json.t, t) => complete;
let redirectCode: (int, string, t) => complete;
let redirect: (string, t) => complete;
let setHeader: (string, string, t) => t;
let setType: (string, t) => t;
let setLinks: (Js.Dict.t(string), t) => t;
let end_: t => complete;
let render: (string, Js.Dict.t(string), 'a, t) => complete;
};
module Next: {
type content;
type t = (Js.undefined(content), Response.t) => complete;
/** value to use as [next] callback argument to invoke the next
middleware */
let middleware: Js.undefined(content);
/** value to use as [next] callback argument to skip middleware
processing for the current route. */
let route: Js.undefined(content);
/** [error e] returns the argument for [next] callback to be propagate
error [e] through the chain of middleware. */
let error: Error.t => Js.undefined(content);
};
module ByteLimit: {
type t =
| B(int)
| Kb(float)
| Mb(float)
| Gb(float);
let b: int => t;
let kb: float => t;
let mb: float => t;
let gb: float => t;
};
module Middleware: {
type t;
type next = Next.t;
let json:
(~inflate: bool=?, ~strict: bool=?, ~limit: ByteLimit.t=?, unit) => t;
let text:
(
~defaultCharset: string=?,
~fileType: string=?,
~inflate: bool=?,
~limit: ByteLimit.t=?,
unit
) =>
t;
let raw:
(~inflate: bool=?, ~fileType: string=?, ~limit: ByteLimit.t=?, unit) => t;
let urlencoded:
(
~extended: bool=?,
~inflate: bool=?,
~limit: ByteLimit.t=?,
~parameterLimit: int=?,
unit
) =>
t;
module type S = {
type f;
let from: f => t;
type errorF;
let fromError: errorF => t;
};
module type ApplyMiddleware = {
type f;
let apply: (f, next, Request.t, Response.t) => unit;
type errorF;
let applyWithError: (errorF, next, Error.t, Request.t, Response.t) => unit;
};
module Make:
(A: ApplyMiddleware) => S with type f = A.f and type errorF = A.errorF;
include
S with
type f = (next, Request.t, Response.t) => complete and
type errorF = (next, Error.t, Request.t, Response.t) => complete;
};
module PromiseMiddleware:
Middleware.S with
type f =
(Middleware.next, Request.t, Response.t) => Js.Promise.t(complete) and
type errorF =
(Middleware.next, Error.t, Request.t, Response.t) =>
Js.Promise.t(complete);
module type Routable = {
type t;
let use: (t, Middleware.t) => unit;
let useWithMany: (t, array(Middleware.t)) => unit;
let useOnPath: (t, ~path: string, Middleware.t) => unit;
let useOnPathWithMany: (t, ~path: string, array(Middleware.t)) => unit;
let get: (t, ~path: string, Middleware.t) => unit;
let getWithMany: (t, ~path: string, array(Middleware.t)) => unit;
let options: (t, ~path: string, Middleware.t) => unit;
let optionsWithMany: (t, ~path: string, array(Middleware.t)) => unit;
let param: (t, ~name: string, Middleware.t) => unit;
let post: (t, ~path: string, Middleware.t) => unit;
let postWithMany: (t, ~path: string, array(Middleware.t)) => unit;
let put: (t, ~path: string, Middleware.t) => unit;
let putWithMany: (t, ~path: string, array(Middleware.t)) => unit;
let patch: (t, ~path: string, Middleware.t) => unit;
let patchWithMany: (t, ~path: string, array(Middleware.t)) => unit;
let delete: (t, ~path: string, Middleware.t) => unit;
let deleteWithMany: (t, ~path: string, array(Middleware.t)) => unit;
};
module MakeBindFunctions: (T: {type t;}) => Routable with type t = T.t;
module Router: {
include Routable;
let make:
(~caseSensitive: bool=?, ~mergeParams: bool=?, ~strict: bool=?, unit) => t;
let asMiddleware: t => Middleware.t;
};
module HttpServer: {
type t;
let on: (t, [
| `request((Request.t, Response.t) => unit)
| `close(unit => unit)
]) => unit
};
let router:
(~caseSensitive: bool=?, ~mergeParams: bool=?, ~strict: bool=?, unit) =>
Router.t;
module App: {
include Routable;
let make: unit => t;
let asMiddleware: t => Middleware.t;
let useRouter: (t, Router.t) => unit;
let useRouterOnPath: (t, ~path: string, Router.t) => unit;
let listen:
(
t,
~port: int=?,
~hostname: string=?,
~onListen: Js.null_undefined(Js.Exn.t) => unit=?,
unit
) =>
HttpServer.t;
let disable: (t, ~name: string) => unit;
let set: (t, string, string) => unit;
};
/** [express ()] creates an instance of the App class.
Alias for [App.make ()] */
let express: unit => App.t;
module Static: {
type options;
type stat;
let defaultOptions: unit => options;
let dotfiles: (options, string) => unit;
let etag: (options, bool) => unit;
let extensions: (options, array(string)) => unit;
let fallthrough: (options, bool) => unit;
let immutable: (options, bool) => unit;
let indexBool: (options, bool) => unit;
let indexString: (options, string) => unit;
let lastModified: (options, bool) => unit;
let maxAge: (options, int) => unit;
let redirect: (options, bool) => unit;
let setHeaders: (options, (Request.t, string, stat) => unit) => unit;
type t;
/** [make directory] creates a static middleware for [directory] */
let make: (string, options) => t;
/** [asMiddleware static] casts [static] to a Middleware type */
let asMiddleware: t => Middleware.t;
};