Skip to content

Commit 8db846f

Browse files
docs: httpRequest reference
Signed-off-by: David Dal Busco <david.dalbusco@outlook.com>
1 parent 683b20f commit 8db846f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

docs/reference/functions/typescript/ic-cdk.mdx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,42 @@ function call<T>(params: CallParams): Promise<T | undefined>;
8181

8282
---
8383

84+
## httpRequest
85+
86+
Performs an HTTP request from a Juno serverless function.
87+
88+
```typescript
89+
function httpRequest(args: HttpRequestArgs): Promise<HttpRequestResult>;
90+
```
91+
92+
📦 Import from `@junobuild/functions/ic-cdk`
93+
94+
#### Parameters:
95+
96+
- `args`: The HTTP request parameters.
97+
- `url`: The requested URL.
98+
- `method`: The HTTP method — `GET`, `POST`, or `HEAD`.
99+
- `headers` (optional): A list of HTTP request headers.
100+
- `body` (optional): The request body as a `Uint8Array`.
101+
- `maxResponseBytes` (optional): The maximal size of the response in bytes.
102+
- `transform` (optional): The name of a query function used to transform the response before consensus. If provided, a corresponding query must be declared using `defineQuery`.
103+
- `isReplicated` (optional): Whether all nodes should perform the request and agree on the response, or just one node. Defaults to all nodes if not specified.
104+
105+
#### Returns:
106+
107+
- `Promise<HttpRequestResult>`: A promise resolving to the HTTP response, containing `status` (bigint), `headers`, and `body` (Uint8Array).
108+
109+
#### Throws:
110+
111+
- `ZodError` if the provided arguments do not match the expected schema.
112+
- `Error` if the HTTP request fails.
113+
114+
#### Notes:
115+
116+
- This function is a JavaScript binding for the Rust function [ic_cdk::management_canister::http_request()](https://docs.rs/ic-cdk/0.19.0/ic_cdk/management_canister/fn.http_request.html).
117+
118+
---
119+
84120
## msgCaller
85121

86122
Returns the Principal ID of the caller of the current function.

0 commit comments

Comments
 (0)