cpthook
API faker and data generator
Last updated 4 years ago by victorzki .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install cpthook 
SYNC missed versions from official npm registry.


Captain Hook

Portable api faker and random data generator built upon 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
$ hook serve

That's basically all there's to it.

Options


Usage: hook [options]

Options:

  init                 Initialize configuration
  serve                Starts server
  -h, --help           output usage information
  -p, --port <port>    Port on which to run server. Defaults to 7000
  -c, --config <file>  Location of configuration json file. (Generated by "hook init").
                       Defaults to ./.cpthook.config
  -d, --dir <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:

{
  "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 with

Next up, we're ready to sail away;

$ hook serve

a GET /companies will (with configuration above) respond with:

[
   {
      "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

Current Tags

  • 1.0.1                                ...           latest (4 years ago)

6 Versions

  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
  • 0.1.1                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
  • 0.0.2                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (11)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |