Giter VIP home page Giter VIP logo

cli-api-mocker's Introduction

cli-api-mocker

CLI wrapper for connect-api-mocker

Installation

npm i -g cli-api-mocker

Usage

After you created your mock files like defined in connect-api-mocker documents you can simply start your mock server with running mockit command inside the root folder of your mocks:

$ mockit

That command will start to serve your mocks on port 9090 by default.

Arguments

mockit command has 4 available arguments.

[-p | --port]     with default value `9090`,
[-f | --fromPath] with default value `/`,
[-t | --toPath]   with default value ``
[-c | --capture]   with default value `false`
[-v | --verbose]   with default value `false`
[-d | --disable-mocks] with default value `false`

These arguments are optional. You can use mockit command with any one of them or any combination of them.

You can see usage examples below:

mockit --port=8989 or mockit -p 8989 for running on port 8989 instead of default port 9090 mockit --fromPath=/api or mockit -f '/api' for running listening paths from /api instead from default path `` mockit --toPath=/mapi or `mockit -t '/mapi'` for forwarding to path `/api` instead of forwarding to default path `/`

Or you can combine any of them like:

mockit --port=8989 --fromPath=/api --toPath=/mapi

Or

mockit -p 8989 -f '/api -t '/mapi'

Note: In next title you will notice config file. If there is a config file, config file will be active. But command line arguments are stronger. So if you use both of them together, command line arguments will override config file.

Configuration with a config file

You can set your configuration with file mock.config.js file in the root of your project directory.

module.exports = {
    port: 9090,
    map: {
        '/api': 'mocks/api'
    }
}

Configuration above will create a mocking server on running port 9090 and serve an api that defined with files in the mocks/api folder with a base url of '/api'. So after running your mockit command in the same folder with that configuration, if you make a request to http://localhost:9090/api/users, api mocker will respond request with file(if exists) in mocks/api/users/GET.json.

Using a proxy

If you also want to use a proxy for requests that you didn't have a mock file, you can define your mock config like that:

module.exports = {
    port: 9090,
    map: {
        '/api': {
            target: 'mocks/api',
            proxy: 'https://api.yourdomain.com'
        }
    }
}

Proxy definition object is a http-proxy-middleware options object. So you can take advantage of all options of http-proxy-middleware library here. Here a more detailed proxy definition example:

module.exports = {
    port: 9090,
    map: {
        '/api': {
            target: 'mocks/api',
            proxy: {
                target: 'https://api.yourdomain.com',
                pathRewrite: {
                    '^/api': ''
                },
                changeOrigin: true,
                secure: false
            }
        }
    }
}

Capture mode

With capture mode, you can automatically create mock files from your api origin responses over proxy. You can enable capture mode by --capture (or -c) command line parameter or capture property in config file:

module.exports = {
    port: 9090,
    map: {
        '/api': {
            target: 'mocks/api',
            proxy: 'https://api.yourdomain.com',
            capture: true
        }
    }
}

When capture mode enabled, if you don't have a mock file for a request and if you have a proxy definition, a mock file will automatically generated for you for successful responses from your origin.

Disabling mocks

You can also disable mocks to just use it as proxy via --disable-mocks cli parameter or disableMocks property in config file.

module.exports = {
    port: 9090,
    map: {
        '/api': {
            target: 'mocks/api',
            proxy: 'https://api.yourdomain.com',
            disableMocks: true
        }
    }
}

cli-api-mocker's People

Contributors

cantsdmr avatar cenkingunlugu avatar muratcorlu avatar viv3kk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cli-api-mocker's Issues

Verbose mode parameter

connect-api-mocker has a verbose mode now. So we need to have that parameter in cli-api-mocker also.

Multipart request support

Api Mocker supports only JSON data in body now. It should also work with multipart/form-data requests.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.