From 525c6f77af6d7c1817f6cce425d179dbed55c5a2 Mon Sep 17 00:00:00 2001 From: Mohamed Ben Makhlouf Date: Sat, 20 Jun 2026 21:20:12 +0200 Subject: [PATCH 1/2] fix(core): make HttpResponse data type generic --- core/src/core-plugins.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/core-plugins.ts b/core/src/core-plugins.ts index a1efe9c901..d068f948f2 100644 --- a/core/src/core-plugins.ts +++ b/core/src/core-plugins.ts @@ -262,11 +262,11 @@ export interface HttpHeaders { [key: string]: string; } -export interface HttpResponse { +export interface HttpResponse { /** * Additional data received with the Http response. */ - data: any; + data: T; /** * The status code received from the Http response. */ From 462a05a2a43d34eb72ea010da5bee180382bc7f2 Mon Sep 17 00:00:00 2001 From: Mohamed Ben Makhlouf Date: Sat, 20 Jun 2026 21:32:25 +0200 Subject: [PATCH 2/2] fix(docs): update HttpResponse examples to use generic type --- core/http.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/core/http.md b/core/http.md index f459597c1f..2cfd053759 100644 --- a/core/http.md +++ b/core/http.md @@ -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 = () => { @@ -54,7 +58,7 @@ const doGet = () => { params: { size: 'XL' }, }; - const response: HttpResponse = await CapacitorHttp.get(options); + const response: HttpResponse = await CapacitorHttp.get(options); // or... // const response = await CapacitorHttp.request({ ...options, method: 'GET' }) @@ -69,7 +73,7 @@ const doPost = () => { data: { foo: 'bar' }, }; - const response: HttpResponse = await CapacitorHttp.post(options); + const response: HttpResponse = await CapacitorHttp.post(options); // or... // const response = await CapacitorHttp.request({ ...options, method: 'POST' }) @@ -205,11 +209,11 @@ Make a Http DELETE Request to a server using native libraries. ### Interfaces -#### HttpResponse +#### HttpResponse | Prop | Type | Description | | ------------- | --------------------------------------------------- | ------------------------------------------------- | -| **`data`** | any | Additional data received with the Http response. | +| **`data`** | T | Additional data received with the Http response. | | **`status`** | number | The status code received from the Http response. | | **`headers`** | HttpHeaders | The headers received from the Http response. | | **`url`** | string | The response URL received from the Http response. | @@ -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 | @@ -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 |