Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alveflo/hook
Portable server and data generator
https://github.com/alveflo/hook
Last synced: 14 days ago
JSON representation
Portable server and data generator
- Host: GitHub
- URL: https://github.com/alveflo/hook
- Owner: alveflo
- License: mit
- Created: 2016-05-20T17:18:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-08-28T13:03:25.000Z (over 8 years ago)
- Last Synced: 2024-11-15T10:57:23.411Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Captain Hook
Portable api faker and random data generator built upon [Faker](https://www.npmjs.com/package/Faker). It serves both as a static file server from either the execution path or given directory. This might come handy if you are working on front end code without a possibility to wire up a backend.
## Install
```
$ (sudo) npm install cpthook --global
```
## Getting started
```
$ hook init
$ (sudo) hook serve
```
That's basically all there's to it. Note that if you're running unix, you might need to run `hook serve` with elevated privileges due to the fs file changes watcher, hence the `sudo`.
## Options
```Usage: hook [options]
Options:
init Initialize configuration
serve Starts server
-h, --help output usage information
-p, --port Port on which to run server. Defaults to 7000
-c, --config Location of configuration json file. (Generated by "hook init").
Defaults to ./.cpthook.config
-d, --dir Directory of which to serve static files from. Defaults to ./```
## Description
Initialize json configuration file;
```
$ hook init
```
`init` creates a `.cpthook.config` file which contains configuration for your web server:
```json
{
"routes": [
{
"route": "/users",
"repeat": 10,
"data": {
"name": "{{name.firstName}}",
"lastname": "{{name.lastName}}",
"email": "{{internet.email}}"
}
},
{
"route": "/companies",
"repeat": 3,
"data": {
"companyName": "{{company.companyName}} {{company.companySuffix}}",
"catchPhrase": "{{company.catchPhrase}}"
}
}
]
}
```The configuration file consists of objects that must contain
- `route` on which respond to
- `repeat` how many json objects to fake. Defaults to 1 (one)
- `data` the data to respond withNext up, we're ready to sail away (Again - note that if you're running unix, you might need to run `hook serve` with elevated privileges due to the fs file changes watcher, hence the `sudo`.);
```
$ (sudo) hook serve
```
a `GET /companies` will (with configuration above) respond with:
```json
[
{
"companyName": "Skiles - Bashirian and Sons",
"catchPhrase": "Operative 5th generation matrix"
},
{
"companyName": "White - Grant Inc",
"catchPhrase": "Virtual intangible ability"
},
{
"companyName": "Douglas, Gorczany and Schultz LLC",
"catchPhrase": "Persistent context-sensitive encoding"
}
]
```
## License
MIT