Products · Dash API
Network
Check whether the phone is online, and send requests, downloads and uploads to your server.
dash.network.status
dash.network.status(callOptions?: CallOptions): DashRequest<NetworkStatus>Whether the phone is online now, and how. It can still be online without reaching a server.
Types: NetworkStatus
dash.network.http.request
dash.network.http.request<ResponseBody = string, RequestBody extends HttpRequestBody = HttpRequestBody>(options: HttpRequest<RequestBody> & HttpReadOptions<ResponseBody>, callOptions?: CallOptions): DashRequest<HttpResponse<ResponseBody>>Like fetch, resolves with any response, even a 404. An object body is sent as JSON.
Types: HttpRequestBody, HttpRequest, HttpReadOptions, HttpResponse
dash.network.http.download
dash.network.http.download(options: HttpDownloadRequest, callOptions?: CallOptions): DashRequest<HttpDownloadResponse>Saves a 2xx response's body, up to 256 MB, to a temporary file.
Types: HttpDownloadRequest, HttpDownloadResponse
dash.network.http.upload
dash.network.http.upload<ResponseBody = string>(options: HttpUploadRequest & HttpReadOptions<ResponseBody>, callOptions?: CallOptions): DashRequest<HttpResponse<ResponseBody>>Sends files to your server as a multipart form, with any fields you add. Pass each file as the DotFile you got, such as from pickPhoto.
Types: HttpUploadRequest, HttpReadOptions, HttpResponse
Types
ConnectionType
type ConnectionType = 'wifi' | 'cellular' | 'other' | 'none';NetworkStatus
| Field | Type | What it is |
|---|---|---|
online | boolean | |
type | ConnectionType |
HttpMethod
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';HttpRequestBody
type HttpRequestBody = string | object;HttpRequest
| Field | Type | What it is |
|---|---|---|
url | string | An https address on a host in network.hosts in dot.json. |
method (optional) | HttpMethod | Default: GET. |
headers (optional) | Record<string, string> | |
body (optional) | RequestBody | Text, or an object, which is sent as JSON. |
HttpResponse
| Field | Type | What it is |
|---|---|---|
ok | boolean | True for a status from 200 to 299. |
status | number | |
statusText | string | |
headers | Record<string, string> | Names are lowercase, such as "content-type". A header sent more than once comes once, with its values joined by ", ". |
body | ResponseBody | Text, or the parsed JSON when you asked for as: 'json'. |
HttpReadOptions
Without as, the response body is text. Pass as: 'json' to get it parsed, typed as the call's ResponseBody.
type HttpReadOptions<ResponseBody> = [ResponseBody] extends [string]
? { as?: 'text' }
: { as: 'json' };HttpDownloadRequest
Also has the fields of HttpRequest.
| Field | Type | What it is |
|---|---|---|
name (optional) | string | The file's name. Without it, the name comes from the response or the address. |
HttpDownloadResponse
type HttpDownloadResponse =
| (Omit<HttpResponse, 'ok' | 'body'> & { ok: true; file: DotFile })
| (Omit<HttpResponse, 'ok'> & { ok: false });Types: HttpResponse, DotFile
HttpUploadFile
| Field | Type | What it is |
|---|---|---|
field | string | The form field the file goes in. |
file | DotFile | |
name (optional) | string | The file name your server sees. Without it, it's the file's own name. |
HttpUploadRequest
| Field | Type | What it is |
|---|---|---|
url | string | An https address on a host in network.hosts in dot.json. |
method (optional) | 'POST' | 'PUT' | 'PATCH' | Default: POST. |
headers (optional) | Record<string, string> | |
fields (optional) | Record<string, string> | Text fields sent along with the files. |
files | HttpUploadFile[] |