@dck/rescript-msw
v1.0.0
Published
ReScript bindings for msw
Downloads
1
Readme
rescript-msw
ReScript bindings for msw (targeted version : ^2.2.1
)
Setup
- 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
{
"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