Skip to content

Commit

Permalink
feat: http request/response type defs and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ozwaldorf committed May 29, 2024
1 parent 703aec4 commit aebbf2e
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions dts/lib.fleek.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,51 @@ declare namespace Fleek {
* Read a given block index from the blockstore
* @param {number} idx - Index of block to read
* @returns {Promise<Uint8Array>}
* @category Fleek Node API
*/
readBlock(idx: number): Promise<Uint8Array>;
}

/** HTTP request methods.
* @category Fleek Node API
*/
type HttpRequestMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD";

/** HTTP request object.
* @property {HttpMethod} method - HTTP Request method.
* @property {string} path - Request path. If empty, defaults to `/`.
* @property {Object.<string, any>} [headers] - List of headers. All entries attempt to be pre-parsed as json/javascript values, otherwise provided as strings.
* @property {Object.<string, any>} [query] - List of query parameters. All entries attempt to be pre-parsed as json/javascript values, otherwise provided as strings.
* @property {any} [body] - Request body. Attempts to be pre-parsed as a json/javascript value, otherwise provided as a string.
* @category Fleek Node API
*/
type HttpRequest = {
method: HttpRequestMethod;
path: String;
headers?: Map<string, string>;
query?: Map<string, any>;
body?: any;
};

/** Valid header formats for an HTTP response.
* @category Fleek Node API
*/
type HttpResponseHeaders =
| Map<string, string>
| Map<string, string[]>
| [string, string][]
| [string, string[]][];

/** HTTP Response object. When returned from a function that's requested over http, it will be used to
* modify the http response. Otherwise, for non-http requests, the raw json object will be sent.
* @property {Number} code - Status code to use. Must be an unsigned integer that fits inside a u16.
* @property {Headers} headers - Array or map of header key values
* @property {any} body - Body to send to client
* @category Fleek Node API
*/
type HttpResponse = {
code: number;
headers: HttpResponseHeaders;
body: any;
};
}

0 comments on commit aebbf2e

Please sign in to comment.