0.4.0 • Published 6 years ago

mockingcat v0.4.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Mockingcat Build Status

Build a mock api server with zero-conf at lightning speed

Getting started

#1 setup

install mockingcat (or use npx)

$ npm i -g mockingcat
# or
$ npm i -D mockingcat

make mock dir to project path

$ mkdir mock

#2 start mockingcat

$ mockingcat
# or
$ npx mockingcat

#3 make mock api - 1

make file mock/get.js

$ touch mock/get.js

now, you can access to mock/get

$ curl http://localhost:8090/mock/get
> {"message":"not implemented yet"}

next, implement mock/get.js

module.exports = {
  method: 'GET',
  handler (request, reply) {
    reply.send({ message: 'hello, world!' })
  }
}

access to mock/get

$ curl http://localhost:8090/mock/get
> {"message":"hello, world!"}

#4 make mock api - 2

next, make mock/user/_id.js, and append this

module.exports = {
  method: 'GET',
  handler (request, reply) {
    reply.send(request.params)
  }
}

you can access to mock/user/_id

$ curl http://localhost:8090/mock/user/hello
> {"id": "hello"}

Detail

config (default)

mockingcat.config.js

module.exports = {
  port: 8090,
  srcDir: './mock',
  baseUrl: '/mock',
  verbose: true,
  middlewares: [], // fastify middleware
  ignore: [/node_modules/]
}

mock file (default)

  • module.exports: { fastify route options } or Array<{ fastify route options }>
module.exports = {
  method: 'GET',
  url: baseUrl + mockFilepath
  handler (request, reply) {
    reply.send({ message: 'not implemented yet' })
  }
}

you can define mock file as fastify route option.

CLI

$ mockingcat --help

Mockingcat
  --help     (-h)
  --version  (-v)
  --port     (-p) : 8090
  --srcdir   (-s) : ./mock
  --baseurl  (-b) : /mock
  --verbose  (-v) : true

Examples

0.4.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago