Skip to content

Releases: DZakh/rescript-rest

v0.9.0

03 Sep 07:22
Compare
Choose a tag to compare

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

26 Aug 10:07
Compare
Choose a tag to compare

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 and Fastify.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

19 Aug 08:45
Compare
Choose a tag to compare
  • 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

08 Aug 08:02
Compare
Choose a tag to compare
  • Add Rest.fetch to simplify calling a route without a client

Full Changelog: v0.5.0...v0.6.0

v0.5.0

04 Aug 08:36
Compare
Choose a tag to compare
  • Changed the path params format to use {} instead of :. So it's compatible with OpenAPI spec
  • The method became a variant instead of a string type

Full Changelog: v0.4.2...v0.5.0

v0.4.2

15 Jul 09:00
Compare
Choose a tag to compare

Add support for rescript-schema V8

Full Changelog: v0.4.1...v0.4.2

v0.4.1

27 Jun 10:46
Compare
Choose a tag to compare
  • Fix ApiFetcher.default implementation

Full Changelog: v0.4.0...v0.4.1

v0.4.0

27 Jun 09:53
Compare
Choose a tag to compare
  • Type-safe responses 🆕
  • Updated ApiFetcher interface and renamed the default fetcher override option from api to fetcher
  • Added ability to define the whole body schema using the s.body method in the variables definition.

Full Changelog: v0.3.0...v0.4.0

v0.3.0

20 Jun 08:38
Compare
Choose a tag to compare
  • Made ~variables in the call function a non-labeled argument
  • Added support for path parameters (without runtime check)

Full Changelog: v0.2.0...v0.3.0

v0.2.0

19 Jun 09:11
Compare
Choose a tag to compare
  • Rename schema to variables 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