ReScript bindings for msw (targeted version : ^2.2.1
)
- Install the module
bun install @dck/rescript-msw
# or
yarn install @dck/rescript-msw
# or
npm install @dck/rescript-msw
- Add it to your
rescript.json
config
{
"bs-dependencies": ["@dck/rescript-msw"]
}
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)
}),
])
Install deps
bun install
Compiles files
bun run dev
Run tests
bun test