Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

LitBuffeet/mock-api-cli

Open more actions menu
 
 

Repository files navigation

Mock json api ? This is a great command line tool for building 'CORS' api, it will create a node server to provide api service by scanning api js/json files in your working directory.

Features

  • support cross domain request
  • support js files that use CommonJS
  • support json file, object or array
  • support changing port, dynamic detecting
  • support static files service
  • support livereload when some api file is modyfied
  • support open api in browser

Looks like this:

Installation

npm install -g mock-api-cli

or 

yarn global add mock-api-cli (recommand)

Usage

cd your-work-directory

get help:

mock-api-cli -h  (you can also use `mac -h`)

tips: you can use 'mac' to replace 'mock-api-cli' command

try it in teminal

mock-api-cli  -o  (or mac -o)

you should create js/json files that defines the api request path, request method and response data, then we will serve those files via api

Api Fields Illustrate

  • path: the request path
  • res: the response data, it is an object or an array
  • type: request method, like 'get', 'post', 'put', 'delete', 'options'

exmple:

dirname/user.js (use CommonJS)

module.exports = {
  path: '/user',
  res: {
    code: Math.random() > .5 ? 200 : 400,
    data: {
      username: 'iceyangcc',
      npm: 'https://www.npmjs.com/package/mock-api-cli'
    }
  }
}
you can custom you logic , you can export an array including many apis

another

list.json (also include "path", "res", "type"...)

[
  {
    path: '/detail/:id',
    type: 'post',
    res: {

    }
  },
  {
    path: '/login',
    type: 'post',
    res: {

    }
  }
]

The invalid object will be ignored

for more detail , visit https://github.com/iceyangcc/mock-api-cli

Techs

  • koa / middleware
  • shell

Know more

my blog: http://blog.nodejs.tech

github

Contact me

iceyangcc@sina.com

About

一个模拟后台JSON格式api接口的命令行工具 mock-api-cli

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 97.5%
  • AppleScript 2.5%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.