Releases: DZakh/rescript-rest
v0.9.0
Authentication header 🆕
For the Authentication header there's a new helper s.auth
which supports Bearer
and Basic
authentication schemes.
let getPosts = Rest.route(() => {
path: "/posts",
method: Get,
variables: s => {
"token": s.auth(Bearer),
},
responses: [
s => s.data(S.array(postSchema)),
],
})
let result = await client.call(
getPosts,
{
"token": "abc",
}
) // ℹ️ It'll do a GET request to http://localhost:3000/posts with the `{"authorization": "Bearer abc"}` headers
Full Changelog: v0.8.0...v0.9.0
v0.8.0
Raw Body 🆕
For some low-level APIs, you may need to send raw body without any additional processing. You can use s.rawBody
method to define a raw body schema. The schema should be string-based, but you can apply transformations to it using s.variant
or s.transform
methods.
let getLogs = Rest.route(() => {
path: "/logs",
method: POST,
variables: s => s.rawBody(S.string->S.transform(s => {
// If you use the route on server side, you should also provide the parse function here,
// But for client side, you can omit it
serialize: logLevel => {
`{
"size": 20,
"query": {
"bool": {
"must": [{"terms": {"log.level": ${logLevels}}}]
}
}
}`
}
})),
responses: [
s => s.data(S.array(S.string)),
],
})
let result = await client.call(
getLogs,
"debug"
) // ℹ️ It'll do a POST request to http://localhost:3000/logs with the body `{"size": 20, "query": {"bool": {"must": [{"terms": {"log.level": ["debug"]}}]}}}` and the headers `{"content-type": "application/json"}`
You can also use routes with rawBody
on the server side with Fastify as any other route:
app->Fastify.route(getLogs, async variables => {
// Do something with variables and return response
})
🧠 Currently Raw Body is sent with the application/json Content Type. If you need support for other Content Types, please open an issue or PR.
Other changes
- Add
Fastify.close
andFastify.listenFirstAvailableLocalPort
bindings - Update injected
ApiFetcher
interface to accept complete fetch args instead of doing JSON.serialize inside of it - Add CI and test coverage for the package
- Remove Beta notice from the docs
Full Changelog: v0.7.0...v0.8.0
v0.7.0
- Added minimal Fastify bindings and integrated it with
rescript-rest
to support server implementation - Improved error for response with unhandled status
- Added type coercion for headers in response
- Lowercase headers before sending to server
- Exposed function to get route params
Full Changelog: v0.6.0...v0.7.0
v0.6.0
- Add
Rest.fetch
to simplify calling a route without a client
Full Changelog: v0.5.0...v0.6.0
v0.5.0
- Changed the path params format to use
{}
instead of:
. So it's compatible with OpenAPI spec - The
method
became a variant instead of astring
type
Full Changelog: v0.4.2...v0.5.0
v0.4.2
Add support for rescript-schema
V8
Full Changelog: v0.4.1...v0.4.2
v0.4.1
- Fix
ApiFetcher.default
implementation
Full Changelog: v0.4.0...v0.4.1
v0.4.0
- Type-safe responses 🆕
- Updated
ApiFetcher
interface and renamed the default fetcher override option fromapi
tofetcher
- Added ability to define the whole body schema using the
s.body
method in thevariables
definition.
Full Changelog: v0.3.0...v0.4.0
v0.3.0
- Made
~variables
in thecall
function a non-labeled argument - Added support for path parameters (without runtime check)
Full Changelog: v0.2.0...v0.3.0
v0.2.0
- Rename
schema
tovariables
in the route definition - Support defining headers
- Support defining query params
- Add json encoding option for query params
Full Changelog: v0.1.0...v0.2.0