Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yaxingson/httpmock

Mock a full fake REST API and provides HTTP request and response services
https://github.com/yaxingson/httpmock

mock restful-api services

Last synced: 24 days ago
JSON representation

Mock a full fake REST API and provides HTTP request and response services

Awesome Lists containing this project

README

        

> officially deployed at https://httpmock.org

## Install

```shell
> npm i httpmock.org --g

```

## Usage

Create a `db.json`、`db.json5` or `db.js` file:

```json
{
"posts":[
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident",
"body": "quia et suscipit suscipit recusandae consequuntur expedita et cum reprehenderit"
},
{
"userId": 1,
"id": 2,
"title": "qui est esse",
"body": "est rerum tempore vitae sequi sint nihil reprehenderit dolor beatae"
}
],
"users":[
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "[email protected]"
}
],
"todos":[
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
},
{
"userId": 1,
"id": 2,
"title": "quis ut nam facilis et officia qui",
"completed": false
}
]
}

```

view json5 format

```json5
{
posts:[
{
userId: 1,
id: 1,
title: "sunt aut facere repellat provident",
body: "quia et suscipit suscipit recusandae consequuntur expedita et cum reprehenderit"
},
{
userId: 1,
id: 2,
title: "qui est esse",
body: "est rerum tempore vitae sequi sint nihil reprehenderit dolor beatae"
}
],
users:[
{
id: 1,
name: "Leanne Graham",
username: "Bret",
email: "[email protected]"
}
],
todos:[
{
userId: 1,
id: 1,
title: "delectus aut autem",
completed: false
},
{
userId": 1,
id": 2,
title: "quis ut nam facilis et officia qui",
completed: false
}
]
}
```

view js format

```js
export default {
posts:[
{
userId: 1,
id: 1,
title: "sunt aut facere repellat provident",
body: "quia et suscipit suscipit recusandae consequuntur expedita et cum reprehenderit"
},
{
userId: 1,
id: 2,
title: "qui est esse",
body: "est rerum tempore vitae sequi sint nihil reprehenderit dolor beatae"
}
],
users:[
{
id: 1,
name: "Leanne Graham",
username: "Bret",
email: "[email protected]"
}
],
todos:[
{
userId: 1,
id: 1,
title: "delectus aut autem",
completed: false
},
{
userId": 1,
id": 2,
title: "quis ut nam facilis et officia qui",
completed: false
}
]
}
```

```shell
> httpmock db.json

# npx
> npx httpmock db.json

```

Based on the example db.json, you'll get the following routes:

```mermaid
flowchart TD
GET ---> /posts
GET ---> /posts/:id
POST ---> /posts
PUT ---> /posts/:id
PATCH ---> /posts/:id
DELETE ---> /posts/:id

```

URL params:

- Conditions: `eq`、`lt`、`lte`、`gt`、`gte` and `ne`

- Range: `start`、`end` and `limit`

- Paginate: `page` and `per_page`(default = 10)

- Sort: `sort` and `reverse`

- Nested and array fields: `x.y.z` and `x.y.z[i]`

- Embed

## Configuration