rescript-rest@0.3.0
is out!
- Made
~variables
in thecall
function a non-labeled argument - Added support for path parameters
Define your API contract somewhere shared, for example, Contract.res
:
let getPost = Rest.route(() => {
path: "/posts/:id",
method: "GET",
variables: s => s.param("id", S.string),
})
Consume the api on the client with a RPC-like interface:
let client = Rest.client(~baseUrl="http://localhost:3000")
let result = await client.call(
Contract.getPost,
"123"
// ^-- Fully typed!
) // ℹ️ It'll do a GET request to http://localhost:3000/posts/123