Skip to content

Commit aebbf2e

Browse files
committed
feat: http request/response type defs and docs
1 parent 703aec4 commit aebbf2e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

dts/lib.fleek.d.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,51 @@ declare namespace Fleek {
4040
* Read a given block index from the blockstore
4141
* @param {number} idx - Index of block to read
4242
* @returns {Promise<Uint8Array>}
43+
* @category Fleek Node API
4344
*/
4445
readBlock(idx: number): Promise<Uint8Array>;
4546
}
47+
48+
/** HTTP request methods.
49+
* @category Fleek Node API
50+
*/
51+
type HttpRequestMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";
52+
53+
/** HTTP request object.
54+
* @property {HttpMethod} method - HTTP Request method.
55+
* @property {string} path - Request path. If empty, defaults to `/`.
56+
* @property {Object.<string, any>} [headers] - List of headers. All entries attempt to be pre-parsed as json/javascript values, otherwise provided as strings.
57+
* @property {Object.<string, any>} [query] - List of query parameters. All entries attempt to be pre-parsed as json/javascript values, otherwise provided as strings.
58+
* @property {any} [body] - Request body. Attempts to be pre-parsed as a json/javascript value, otherwise provided as a string.
59+
* @category Fleek Node API
60+
*/
61+
type HttpRequest = {
62+
method: HttpRequestMethod;
63+
path: String;
64+
headers?: Map<string, string>;
65+
query?: Map<string, any>;
66+
body?: any;
67+
};
68+
69+
/** Valid header formats for an HTTP response.
70+
* @category Fleek Node API
71+
*/
72+
type HttpResponseHeaders =
73+
| Map<string, string>
74+
| Map<string, string[]>
75+
| [string, string][]
76+
| [string, string[]][];
77+
78+
/** HTTP Response object. When returned from a function that's requested over http, it will be used to
79+
* modify the http response. Otherwise, for non-http requests, the raw json object will be sent.
80+
* @property {Number} code - Status code to use. Must be an unsigned integer that fits inside a u16.
81+
* @property {Headers} headers - Array or map of header key values
82+
* @property {any} body - Body to send to client
83+
* @category Fleek Node API
84+
*/
85+
type HttpResponse = {
86+
code: number;
87+
headers: HttpResponseHeaders;
88+
body: any;
89+
};
4690
}

0 commit comments

Comments
 (0)