ZEPETO.Multiplay.HttpService
Type | Description |
|---|---|
Enumeration of constants specifying the HTTP Content-Type. | |
HttpBodyType | Type alias for HTTP Body content, which can be either plain text or a key-value object. |
HttpHeader | Type alias for HTTP Headers, representing a key-value object. |
Enumeration of constants specifying reasons for failure in HTTP requests. | |
HttpError | Represents an error that occurred during an HTTP request. |
HttpResponse | Represents an HTTP Response. |
HttpService | HttpService provides an API to establish HTTP connections with external web services and make requests. - Ensure using HTTPS protocol; HTTP is supported only in the development environment. - Requests are limited to ports 80 and 443. - The maximum size for request and response bodies is 16KB. - Keep requests per minute below 500 to avoid potential limitations on the World service due to excessive requests. - Requests will fail if external web services do not respond within 5 seconds. - Ensure that the Content-Type in response headers matches values defined in HttpContentType enum to prevent request failures. - Due to potential web request failures for various reasons, it's recommended to code defensively. |
HttpContentType
enum
Enumeration of constants specifying the HTTP Content-Type.
Name | Value | Description |
|---|---|---|
ApplicationJson | "application/json" | Represents application/json content type. |
ApplicationXml | "application/xml" | Represents application/xml content type. |
ApplicationUrlEncoded | "application/x-www-form-urlencoded" | Represents application/x-www-form-urlencoded content type. |
TextPlain | "text/plain" | Represents text/plain content type. |
TextXml | "text/xml" | Represents text/xml content type. |
HttpBodyType
delegate
Type alias for HTTP Body content, which can be either plain text or a key-value object.
string | { [key: string]: any; }
HttpHeader
delegate
Type alias for HTTP Headers, representing a key-value object.
{ [key: string]: string | number; }
HttpErrorType
enum
Enumeration of constants specifying reasons for failure in HTTP requests.
Name | Value | Description |
|---|---|---|
ERR_ACCESS_DENIED | "ERR_ACCESS_DENIED" | Error: Access denied. |
ERR_LENGTH_REQUIRED | "ERR_LENGTH_REQUIRED" | Error: Length required. |
HttpError
interface · extends Error
Represents an error that occurred during an HTTP request.
Properties
Name | Type | Description |
|---|---|---|
message | string | Error message. |
code | string | Error code defined as a value from HttpErrorType enum. |
HttpResponse
interface
Represents an HTTP Response.
Properties
Name | Type | Description |
|---|---|---|
statusCode | number | The status code of the response. Typically, 200 indicates a successful request. |
statusText | string | The status message corresponding to the status code. Typically, "OK" indicates a successful request. |
response | string | The body of the HTTP response, which may vary in format based on the response's Content-Type. It is recommended to use an appropriate parser based on the specific Content-Type received. |
HttpService
interface
HttpService provides an API to establish HTTP connections with external web services and make requests.
- Ensure using HTTPS protocol; HTTP is supported only in the development environment.
- Requests are limited to ports 80 and 443.
- The maximum size for request and response bodies is 16KB.
- Keep requests per minute below 500 to avoid potential limitations on the World service due to excessive requests.
- Requests will fail if external web services do not respond within 5 seconds.
- Ensure that the Content-Type in response headers matches values defined in HttpContentType enum to prevent request failures.
- Due to potential web request failures for various reasons, it's recommended to code defensively.
Methods
getAsync
getAsync(url: string, headers?: HttpHeader) → Promise<HttpResponse>
Asynchronously performs an HTTP GET request. Throws HttpError.
Parameter | Type | Description |
|---|---|---|
url | string | The web address to send the request. |
headers (optional) | HttpHeader | HTTP request headers. (Optional) |
Returns: Promise<HttpResponse> — Promise resolved with the HttpResponse object upon completion.
postAsync
postAsync(url: string, body: HttpBodyType, headers?: HttpHeader) → Promise<HttpResponse>
Perform HTTP POST requests asynchronously. Throws HttpError.
Parameter | Type | Description |
|---|---|---|
url | string | The web address to send the request. |
body | HttpBodyType | Request body content. |
headers (optional) | HttpHeader | HTTP request headers. (Optional) |
Returns: Promise<HttpResponse> — Promise resolved with the HttpResponse object upon completion.
postAsync
postAsync(url: string, body: HttpBodyType, httpContentType: HttpContentType, headers?: HttpHeader) → Promise<HttpResponse>
Perform HTTP POST requests asynchronously. Throws HttpError. When using this signature, if you add 'Content-Type' to headers, it will be overwritten by what is specified in httpContentType.
Parameter | Type | Description |
|---|---|---|
url | string | The web address to send the request. |
body | HttpBodyType | Request body content. |
httpContentType | Specifies the request Content-Type header. | |
headers (optional) | HttpHeader | HTTP request headers. (Optional) |
Returns: Promise<HttpResponse> — Promise resolved with the HttpResponse object upon completion.