https://github.com/patrickhulce/mock-api
Quick and dirty mock API.
https://github.com/patrickhulce/mock-api
Last synced: about 1 year ago
JSON representation
Quick and dirty mock API.
- Host: GitHub
- URL: https://github.com/patrickhulce/mock-api
- Owner: patrickhulce
- Created: 2016-03-03T05:43:41.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-03T05:55:33.000Z (over 10 years ago)
- Last Synced: 2024-10-19T00:48:46.843Z (over 1 year ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mock-api
Quick and dirty mock API.
## Usage
### Route Definition Object
A route definition object outlines what the API response is to be on a given path. Currently supported fields are `path`, `statusCode`, and `body`.
If the body value is a string, it will be parsed as a [lodash template](https://lodash.com/docs#template) using the request object as the source.
### Static Routes via File
Easisest, define route objects in a JSON file.
```json
{
"/my/static/route": {
"statusCode": 201,
"body": { "body": "to", "return": "as-is" }
},
"/echo/route": {
"body": {
"id": "<%= body.id %>",
"mode": "<%= query.my_query_string_value %>",
}
}
}
```
### Dynamic Routes via POST
You can also define routes programmatically via the `/configure` route. Clear all currently set routes with `POST /clear`
`curl -X POST http://localhost:3100/configure -H 'Content-Type: application/json' -d '{"path":"/foo", "body": {"hello": "world"}}'`