You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a simple OpenAPI without special feature, can come with
limitations for non-jsonable request/response
Closes: #163
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **Documentation**
- Enhanced the installation and setup guide for OpenAPILink with clear
multi-package manager instructions.
- Added detailed sections covering limitations, CORS policy
requirements, client context usage, and keep-alive behavior.
- Introduced new sections for OpenAPILink functionality and
serialization options.
- **New Features**
- Introduced new package dependencies to expand OpenAPI client
capabilities and improve modularity.
- Added new exports for the fetch module and enhanced serialization
options in the OpenAPI client.
- **Bug Fixes**
- Refined error handling with updated status code validations, ensuring
more consistent response behavior.
- Improved header merging logic to handle various scenarios effectively.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Copy file name to clipboardExpand all lines: apps/content/docs/openapi/client/openapi-link.md
+140-1
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,145 @@ description: Details on using OpenAPILink in oRPC clients.
7
7
8
8
OpenAPILink enables communication with an [OpenAPIHandler](/docs/openapi/openapi-handler) on your server using HTTP/Fetch.
9
9
10
+
## Installation
11
+
12
+
::: code-group
13
+
14
+
```sh [npm]
15
+
npm install @orpc/openapi-client@latest
16
+
```
17
+
18
+
```sh [yarn]
19
+
yarn add @orpc/openapi-client@latest
20
+
```
21
+
22
+
```sh [pnpm]
23
+
pnpm add @orpc/openapi-client@latest
24
+
```
25
+
26
+
```sh [bun]
27
+
bun add @orpc/openapi-client@latest
28
+
```
29
+
30
+
```sh [deno]
31
+
deno install npm:@orpc/openapi-client@latest
32
+
```
33
+
34
+
:::
35
+
36
+
## Setup
37
+
38
+
To use `OpenAPILink`, you must have a [contract router](/docs/contract-first/define-contract#contract-router) and a server configured with an [OpenAPIHandler](/docs/openapi/openapi-handler).
39
+
40
+
::: info
41
+
A normal [router](/docs/router) works as a contract router as long as it does not include a [lazy router](/docs/router#lazy-router). You can also unlazy a router using the [unlazyRouter](/docs/advanced/mocking#using-the-implementer) utility.
Wrap your client with `JsonifiedClient` to ensure it accurately reflects the server responses.
65
+
:::
66
+
67
+
## Limitations
68
+
69
+
Unlike [RPCLink](/docs/client/rpc-link), `OpenAPILink` has some constraints:
70
+
71
+
- Payloads containing a `Blob` or `File` (outside the root level) must use `multipart/form-data` and serialized using [Bracket Notation](/docs/openapi/bracket-notation).
72
+
- For `GET` requests, the payload must be sent as `URLSearchParams` and serialized using [Bracket Notation](/docs/openapi/bracket-notation).
73
+
74
+
:::warning
75
+
In these cases, both the request and response are subject to the limitations of [Bracket Notation Limitations](/docs/openapi/bracket-notation#limitations). Additionally, oRPC converts data to strings (exclude `null` and `undefined` will not be represented).
76
+
:::
77
+
78
+
## CORS policy
79
+
80
+
`OpenAPILink` requires access to the `Content-Disposition` to distinguish file responses from other responses whe file has a common MIME type like `application/json`, `plain/text`, etc. To enable this, include `Content-Disposition` in your CORS policy's `Access-Control-Expose-Headers`:
81
+
82
+
```ts
83
+
const handler =newOpenAPIHandler(router, {
84
+
plugins: [
85
+
newCORSPlugin({
86
+
exposeHeaders: ['Content-Disposition'],
87
+
}),
88
+
],
89
+
})
90
+
```
91
+
92
+
## Using Client Context
93
+
94
+
Client context lets you pass extra information when calling procedures and dynamically modify RPCLink’s behavior.
Interested in OpenAPILink support? Help us prioritize this feature by casting your vote on [Github](https://github.com/unnoq/orpc/issues/163)
124
+
If a property in `ClientContext` is required, oRPC enforces its inclusion when calling procedures.
125
+
:::
126
+
127
+
## SSE Like Behavior
128
+
129
+
Unlike traditional SSE, the [Event Iterator](/docs/event-iterator) does not automatically retry on error. To enable automatic retries, refer to the [Client Retry Plugin](/docs/plugins/client-retry).
130
+
131
+
## Event Iterator Keep Alive
132
+
133
+
:::warning
134
+
These options for sending [Event Iterator](/docs/event-iterator) from **client to the server**, not from **the server to client** as used in [RPCHandler Event Iterator Keep Alive](/docs/rpc-handler#event-iterator-keep-alive) or [OpenAPIHandler Event Iterator Keep Alive](/docs/openapi/openapi-handler#event-iterator-keep-alive).
135
+
136
+
**In 99% of cases, you don't need to configure these options.**
12
137
:::
138
+
139
+
To keep [Event Iterator](/docs/event-iterator) connections alive, `RPCLink` periodically sends a ping comment to the server. You can configure this behavior using the following options:
140
+
141
+
-`eventIteratorKeepAliveEnabled` (default: `true`) – Enables or disables pings.
142
+
-`eventIteratorKeepAliveInterval` (default: `5000`) – Time between pings (in milliseconds).
143
+
-`eventIteratorKeepAliveComment` (default: `''`) – Custom content for ping messages.
0 commit comments