@dck/rescript-msw

1.0.0 • Public • Published

rescript-msw

ReScript bindings for msw (targeted version : ^2.2.1)

Setup

  1. Install the module
bun install @dck/rescript-msw
# or
yarn install @dck/rescript-msw
# or
npm install @dck/rescript-msw
  1. Add it to your rescript.json config
{
  "bsc-dependencies": ["@dck/rescript-msw"]
}

Usage

The functions can be accessed through Msw module.

@spice
type example = {
  id: string,
  username: string,
  age: int
}

let worker = Msw.setupWorker([
  Msw.Http.get("https://fakeapi.com/test", _ => {
    let ex: example = {
      id: "id",
      username: "mock",
      age: 31
    }
    Msw.HttpResponse.jsonUnsafe(ex)
  }),
  Msw.Http.get("https://fakeapi.com/params/:id", ({params}) => {
    let paramsId = params->Js.Dict.get("id")

    let ex: example = {
      id: paramsId->Option.getOr("1"),
      username: "mock",
      age: 31,
    }
    Msw.HttpResponse.json(ex->example_encode)
  }),
])

Development

Install deps

bun install

Compiles files

bun run dev

Run tests

bun test

Readme

Keywords

Package Sidebar

Install

npm i @dck/rescript-msw

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

4.82 kB

Total Files

4

Last publish

Collaborators

  • dck