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
@@ -142,6 +145,30 @@ Routes are the main building block of the library and a perfect way to describe
142
145
143
146
For every route you can describe how the HTTP transport will look like, the `'input` and `'output` types, as well as add additional metadata to use for OpenAPI.
144
147
148
+
### RPC-like abstraction
149
+
150
+
Alternatively if you use ReScript Rest both on client and server and you don't care about how the data is transfered, there's a helper built on top of `Rest.route`. Just define input and output schemas and done:
151
+
152
+
```rescript
153
+
let getPosts = Rest.rpc(() => {
154
+
input: S.sceham(s => {
155
+
"skip": s.matches(S.int),
156
+
"take": s.matches(S.int),
157
+
"page": s.matches(S.option(S.int)),
158
+
}),
159
+
output: S.array(postSchema),
160
+
})
161
+
162
+
let result = await Contract.getPosts->Rest.fetch(
163
+
{"skip": 0, "take": 10, "page": Some(1)}
164
+
)
165
+
// ℹ️ It'll do a POST request to http://localhost:3000/getPosts with the `{"skip": 0, "take": 10, "page": 1}` body and application/json Content Type
166
+
```
167
+
168
+
This is a code snipped from the super simple example above. Note how I only changed the route definition, but the fetching call stayed untouched. The same goes for the server implementation - if the input and output types of the route don't change there's no need to rewrite any logic.
169
+
170
+
> 🧠 The path for the route is either taken from `operationId` or the name of the route variable.
171
+
145
172
### Path Parameters
146
173
147
174
You can define path parameters by adding them to the `path` strin with a curly brace `{}` including the parameter name. Then each parameter must be defined in `input` with the `s.param` method.
@@ -429,7 +456,7 @@ let fetch = Rest.fetch(~client, ...)
429
456
430
457
### API Fetcher
431
458
432
-
You can override the client fetching logic by passing the `~apiFetcher` param.
459
+
You can override the client fetching logic by passing the `~fetcher` param.
0 commit comments