0.0.3 • Published 8 months ago

httpmock.org v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

officially deployed at https://httpmock.org

Install

> npm i httpmock.org --g

Usage

Create a db.jsondb.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": "Sincere@april.biz"
	  }
	],
	"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: "Sincere@april.biz"
	  }
	],
	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: "Sincere@april.biz"
	  }
	],
	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: eqltltegtgte and ne

  • Range: startend 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

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago