Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 1759

[ANN] rescript-rest - RPC-like client, contract, and server implementation for a pure REST API

$
0
0

:new: rescript-rest@0.3.0 is out!

  • Made ~variables in the call 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

Viewing all articles
Browse latest Browse all 1759

Trending Articles