Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/yaxingson/httpmock
- Owner: yaxingson
- License: mit
- Created: 2024-08-19T07:35:33.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-11-18T07:32:50.000Z (2 months ago)
- Last Synced: 2024-12-18T10:49:48.010Z (about 1 month ago)
- Topics: mock, restful-api, services
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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