Skip to content

Commit

Permalink
http (client): add declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliy-art committed Mar 1, 2024
1 parent 29b2ce2 commit e313234
Show file tree
Hide file tree
Showing 13 changed files with 756 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tarantoolscript",
"version": "0.9.1",
"version": "0.10.0",
"author": "Vitaliy Artemov [email protected]",
"description": "TypeScript definitions for Tarantool Lua API.",
"repository": {
Expand Down
229 changes: 229 additions & 0 deletions src/builtin/http.client/Client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
import { ClientStat } from './ClientStat';
import { HttpMethod } from './HttpMethod';
import { IoObject } from './IoObject';
import { RequestOptions } from './RequestOptions';
import { ResponseObject } from './ResponseObject';

export interface Client {
/**
* Make an HTTP request and receive a response.
* @param method A request HTTP method. Possible values: `GET`, `POST`, `PUT`, `PATCH`, `OPTIONS`, `HEAD`, `DELETE`, `TRACE`, `CONNECT`.
* @param url A request URL, for example, `https://httpbin.org/get`.
* @param body A request body.
* @param opts Request options.
* @returns This method returns one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
request(method: HttpMethod, url: string, body?: string, opts: RequestOptions & { chunked: true }): IoObject;

/**
* Make an HTTP request and receive a response.
* @param method A request HTTP method. Possible values: `GET`, `POST`, `PUT`, `PATCH`, `OPTIONS`, `HEAD`, `DELETE`, `TRACE`, `CONNECT`.
* @param url A request URL, for example, `https://httpbin.org/get`.
* @param body A request body.
* @param opts Request options.
* @returns This method returns one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
request(method: HttpMethod, url: string, body?: string, opts?: RequestOptions): ResponseObject;

/**
* Make a `GET` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/get`.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
get(url: string, opts: RequestOptions & { chunked: true }): IoObject;

/**
* Make a `GET` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/get`.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
get(url: string, opts?: RequestOptions): ResponseObject;

/**
* Make a `POST` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/post`.
* @param body A request body.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
post(url: string, body?: AnyTable, opts: RequestOptions & { chunked: true }): IoObject;

/**
* Make a `POST` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/post`.
* @param body A request body.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
post(url: string, body?: AnyTable, opts?: RequestOptions): ResponseObject;

/**
* Make a `PUT` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/put`.
* @param body A request body.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
put(url: string, body?: AnyTable, opts: RequestOptions & { chunked: true }): IoObject;

/**
* Make a `PUT` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/put`.
* @param body A request body.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
put(url: string, body?: AnyTable, opts?: RequestOptions): ResponseObject;

/**
* Make a `PATCH` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/patch`.
* @param body A request body.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
patch(url: string, body?: AnyTable, opts: RequestOptions & { chunked: true }): IoObject;

/**
* Make a `PATCH` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/patch`.
* @param body A request body.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
patch(url: string, body?: AnyTable, opts?: RequestOptions): ResponseObject;

/**
* Make a `DELETE` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/delete`.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
delete(url: string, opts: RequestOptions & { chunked: true }): IoObject;

/**
* Make a `DELETE` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/delete`.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
delete(url: string, opts?: RequestOptions): ResponseObject;

/**
* Make a `HEAD` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/head`.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
head(url: string, opts: RequestOptions & { chunked: true }): IoObject;

/**
* Make a `HEAD` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/head`.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
head(url: string, opts?: RequestOptions): ResponseObject;

/**
* Make a `OPTIONS` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/options`.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
options(url: string, opts: RequestOptions & { chunked: true }): IoObject;

/**
* Make a `OPTIONS` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/options`.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
options(url: string, opts?: RequestOptions): ResponseObject;

/**
* Make a `TRACE` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/trace`.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
trace(url: string, opts: RequestOptions & { chunked: true }): IoObject;

/**
* Make a `TRACE` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/trace`.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
trace(url: string, opts?: RequestOptions): ResponseObject;

/**
* Make a `CONNECT` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/connect`.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
connect(url: string, opts: RequestOptions & { chunked: true }): IoObject;

/**
* Make a `CONNECT` request and receive a response.
* @param url A request URL, for example, `https://httpbin.org/connect`.
* @param opts Request options.
* @returns This method might return one of the following objects:
* - `response_object`;
* - `io_object` if `request_options.chunked` is set to `true`.
*/
connect(url: string, opts?: RequestOptions): ResponseObject;

/**
* Get a table with statistics for the HTTP client.
*/
stat(): ClientStat;

/**
* Since: `2.11.0`.
*
* Decoders used to deserialize response data based on the `Content-Type` header value.
*/
decoders: { [ key: string ]: (this: void) => (body: string, _content_type: unknown) => unknown };
}
11 changes: 11 additions & 0 deletions src/builtin/http.client/ClientOptions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface ClientOptions {
/**
* Specifies the maximum number of entries in the cache. This option affects libcurl `CURLMOPT_MAXCONNECTS`. The default is `-1`.
*/
max_connections?: number;

/**
* Specifies the maximum number of active connections. This option affects libcurl `CURLMOPT_MAX_TOTAL_CONNECTIONS`.
*/
max_total_connections?: number;
}
36 changes: 36 additions & 0 deletions src/builtin/http.client/ClientStat.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export interface ClientStat {
/**
* The number of currently executing requests.
*/
active_requests: number;

/**
* The total number of sockets added into an event loop.
*/
sockets_added: number;

/**
* The total number of sockets deleted from an event loop.
*/
sockets_deleted: number;

/**
* The total number of requests.
*/
total_requests: number;

/**
* The total number of requests that returned HTTP `200 OK` responses.
*/
http_200_responses: number;

/**
* The total number of requests that returned non-`200 OK` responses.
*/
http_other_responses: number;

/**
* The total number of failed requests, including system, curl, and HTTP errors.
*/
failed_requests: number;
}
Loading

0 comments on commit e313234

Please sign in to comment.