Products · Dash API

Network

Check whether the phone is online, and send requests, downloads and uploads to your server.

dash.network.status

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
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

TypeScript
type ConnectionType = 'wifi' | 'cellular' | 'other' | 'none';

NetworkStatus

FieldTypeWhat it is
onlineboolean
typeConnectionType

HttpMethod

TypeScript
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';

HttpRequestBody

TypeScript
type HttpRequestBody = string | object;

HttpRequest

FieldTypeWhat it is
urlstringAn https address on a host in network.hosts in dot.json.
method (optional)HttpMethodDefault: GET.
headers (optional)Record<string, string>
body (optional)RequestBodyText, or an object, which is sent as JSON.

HttpResponse

FieldTypeWhat it is
okbooleanTrue for a status from 200 to 299.
statusnumber
statusTextstring
headersRecord<string, string>Names are lowercase, such as "content-type". A header sent more than once comes once, with its values joined by ", ".
bodyResponseBodyText, 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.

TypeScript
type HttpReadOptions<ResponseBody> = [ResponseBody] extends [string]
  ? { as?: 'text' }
  : { as: 'json' };

HttpDownloadRequest

Also has the fields of HttpRequest.

FieldTypeWhat it is
name (optional)stringThe file's name. Without it, the name comes from the response or the address.

HttpDownloadResponse

TypeScript
type HttpDownloadResponse =
  | (Omit<HttpResponse, 'ok' | 'body'> & { ok: true; file: DotFile })
  | (Omit<HttpResponse, 'ok'> & { ok: false });

Types: HttpResponse, DotFile

HttpUploadFile

FieldTypeWhat it is
fieldstringThe form field the file goes in.
fileDotFile
name (optional)stringThe file name your server sees. Without it, it's the file's own name.

HttpUploadRequest

FieldTypeWhat it is
urlstringAn 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.
filesHttpUploadFile[]

Keep reading