Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions core/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export default config;
## Example

```typescript
import { CapacitorHttp } from '@capacitor/core';
import { CapacitorHttp, type HttpResponse } from '@capacitor/core';

interface MyResponse {
foo: string;
}

// Example of a GET request
const doGet = () => {
Expand All @@ -54,7 +58,7 @@ const doGet = () => {
params: { size: 'XL' },
};

const response: HttpResponse = await CapacitorHttp.get(options);
const response: HttpResponse<MyResponse> = await CapacitorHttp.get(options);

// or...
// const response = await CapacitorHttp.request({ ...options, method: 'GET' })
Expand All @@ -69,7 +73,7 @@ const doPost = () => {
data: { foo: 'bar' },
};

const response: HttpResponse = await CapacitorHttp.post(options);
const response: HttpResponse<MyResponse> = await CapacitorHttp.post(options);

// or...
// const response = await CapacitorHttp.request({ ...options, method: 'POST' })
Expand Down Expand Up @@ -205,11 +209,11 @@ Make a Http DELETE Request to a server using native libraries.
### Interfaces


#### HttpResponse
#### HttpResponse<T = any>

| Prop | Type | Description |
| ------------- | --------------------------------------------------- | ------------------------------------------------- |
| **`data`** | <code>any</code> | Additional data received with the Http response. |
| **`data`** | <code>T</code> | Additional data received with the Http response. |
| **`status`** | <code>number</code> | The status code received from the Http response. |
| **`headers`** | <code><a href="#httpheaders">HttpHeaders</a></code> | The headers received from the Http response. |
| **`url`** | <code>string</code> | The response URL received from the Http response. |
Expand Down Expand Up @@ -279,9 +283,9 @@ https://nodejs.org/api/buffer.html#class-blob

#### ArrayBuffer

Represents a raw buffer of binary data, which is used to store data for the
different typed arrays. ArrayBuffers cannot be read from or written to directly,
but can be passed to a typed array or DataView Object to interpret the raw
Represents a raw buffer of binary data, which is used to store data for the
different typed arrays. ArrayBuffers cannot be read from or written to directly,
but can be passed to a typed array or DataView Object to interpret the raw
buffer as needed.

| Prop | Type | Description |
Expand Down Expand Up @@ -542,7 +546,7 @@ https://nodejs.org/api/url.html#class-urlsearchparams

#### Uint8Array

A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the
A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the
requested number of bytes could not be allocated an exception is raised.

| Prop | Type | Description |
Expand Down
4 changes: 2 additions & 2 deletions core/src/core-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ export interface HttpHeaders {
[key: string]: string;
}

export interface HttpResponse {
export interface HttpResponse<T = any> {
/**
* Additional data received with the Http response.
*/
data: any;
data: T;
/**
* The status code received from the Http response.
*/
Expand Down