https://github.com/dckt/rescript-msw
ReScript bindings for MSW library
https://github.com/dckt/rescript-msw
Last synced: about 1 month ago
JSON representation
ReScript bindings for MSW library
- Host: GitHub
- URL: https://github.com/dckt/rescript-msw
- Owner: DCKT
- Created: 2024-02-21T03:34:18.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-21T03:59:19.000Z (about 1 year ago)
- Last Synced: 2025-02-11T13:27:06.810Z (3 months ago)
- Language: ReScript
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# rescript-msw
ReScript bindings for [msw](https://mswjs.io/) (targeted version : `^2.2.1`)
## Setup
1. Install the module
```bash
bun install @dck/rescript-msw
# or
yarn install @dck/rescript-msw
# or
npm install @dck/rescript-msw
```2. Add it to your `rescript.json` config
```json
{
"bs-dependencies": ["@dck/rescript-msw"]
}
```## Usage
The functions can be accessed through `Msw` module.
```rescript
@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
```bash
bun install
```Compiles files
```bash
bun run dev
```Run tests
```bash
bun test
```