# Network (/docs/products/dash-dots/reference/dash-api/network)

## `dash.network.status`

```ts
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`](/docs/products/dash-dots/reference/dash-api/network#networkstatus)

## `dash.network.http.request`

```ts
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`](/docs/products/dash-dots/reference/dash-api/network#httprequestbody), [`HttpRequest`](/docs/products/dash-dots/reference/dash-api/network#httprequest), [`HttpReadOptions`](/docs/products/dash-dots/reference/dash-api/network#httpreadoptions), [`HttpResponse`](/docs/products/dash-dots/reference/dash-api/network#httpresponse)

## `dash.network.http.download`

```ts
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`](/docs/products/dash-dots/reference/dash-api/network#httpdownloadrequest), [`HttpDownloadResponse`](/docs/products/dash-dots/reference/dash-api/network#httpdownloadresponse)

## `dash.network.http.upload`

```ts
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`](/docs/products/dash-dots/reference/dash-api/network#httpuploadrequest), [`HttpReadOptions`](/docs/products/dash-dots/reference/dash-api/network#httpreadoptions), [`HttpResponse`](/docs/products/dash-dots/reference/dash-api/network#httpresponse)

## Types

### `ConnectionType`

```ts
type ConnectionType = 'wifi' | 'cellular' | 'other' | 'none';
```

### `NetworkStatus`

| Field    | Type                                                                                   | What it is |
| -------- | -------------------------------------------------------------------------------------- | ---------- |
| `online` | `boolean`                                                                              |            |
| `type`   | [`ConnectionType`](/docs/products/dash-dots/reference/dash-api/network#connectiontype) |            |

### `HttpMethod`

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

### `HttpRequestBody`

```ts
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`](/docs/products/dash-dots/reference/dash-api/network#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`.

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

### `HttpDownloadRequest`

Also has the fields of [`HttpRequest`](/docs/products/dash-dots/reference/dash-api/network#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`

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

Types: [`HttpResponse`](/docs/products/dash-dots/reference/dash-api/network#httpresponse), [`DotFile`](/docs/products/dash-dots/reference/dash-api/files#dotfile)

### `HttpUploadFile`

| Field             | Type                                                                   | What it is                                                            |
| ----------------- | ---------------------------------------------------------------------- | --------------------------------------------------------------------- |
| `field`           | `string`                                                               | The form field the file goes in.                                      |
| `file`            | [`DotFile`](/docs/products/dash-dots/reference/dash-api/files#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[]`](/docs/products/dash-dots/reference/dash-api/network#httpuploadfile) |                                                              |
