httpmock.org
v0.0.3
Published
mock a full fake REST API and provides HTTP request and response services
Readme
officially deployed at https://httpmock.org
Install
> npm i httpmock.org --g
Usage
Create a db.json、db.json5 or db.js file:
{
"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
}
]
}
{
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
}
]
}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
}
]
}> httpmock db.json
# npx
> npx httpmock db.json
Based on the example db.json, you'll get the following routes:
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、gteandneRange:
start、endandlimitPaginate:
pageandper_page(default = 10)Sort:
sortandreverseNested and array fields:
x.y.zandx.y.z[i]Embed
