-
RPC-like client with no codegen
Fully typed RPC-like client, with no need for code generation! -
API design agnostic
REST? HTTP-RPC? Your own custom hybrid? rescript-rest doesn't care! -
First class DX
Less unnecessary builds in monorepos, instant compile-time errors, and instantly view endpoint implementations through your IDEs "go to definition" -
Small package size and tree-shakable routes
Routes comple to simple functions which allows tree-shaking only possible with ReScript.
β οΈ rescript-rest is currently in Beta and has very limited list of features. Be aware of possible breaking changesβΊοΈ
β οΈ rescript-rest relies on rescript-schema which useseval
for parsing. It's usually fine but might not work in some environments like Cloudflare Workers or third-party scripts used on pages with the script-src header.
Install peer dependencies rescript
(instruction) and rescript-schema
(instruction).
Then run:
npm install rescript-rest
Add rescript-rest
to bs-dependencies
in your rescript.json
:
{
...
+ "bs-dependencies": ["rescript-rest"],
}
Create Contract.res
and define your routes:
// Contract.res
let createGame = Rest.route(() => {
path: "/game",
method: "POST",
schema: s => {
"userName": s.field("user_name", S.string),
},
})
π§ Currently
rescript-rest
supports onlyclient
, but the idea is to reuse the file both forclient
andserver
.
Now you can use the contract to perform type-safe calls to your server:
// Client.res
let client = Rest.client(~baseUrl="http://localhost:3000")
let _ = await client.call(Contract.createGame, ~variables={"userName": "Dmitry"})
- Support path params
- Implement type-safe response
- Support passing headers and fetch options
- Generate OpenAPI from Contract
- Generate Contract from OpenAPI
- Integrate with Fastify on server-side