All Projects → arenahito → instant-mock

arenahito / instant-mock

Licence: MIT license
Quick and Easy web API mock server.

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects
HTML
75241 projects

Projects that are alternatives of or similar to instant-mock

mockingbird
🐦 Decorator Powered TypeScript Library for Creating Mocks
Stars: ✭ 70 (+159.26%)
Mutual labels:  mock, test
Mockswift
MockSwift is a Mock library written in Swift.
Stars: ✭ 56 (+107.41%)
Mutual labels:  mock, test
Shellspec
A full-featured BDD unit testing framework for bash, ksh, zsh, dash and all POSIX shells
Stars: ✭ 375 (+1288.89%)
Mutual labels:  mock, test
Mastermind
Man in the middle testing
Stars: ✭ 341 (+1162.96%)
Mutual labels:  mock, test
Nsubstitute
A friendly substitute for .NET mocking libraries.
Stars: ✭ 1,646 (+5996.3%)
Mutual labels:  mock, test
Fakerest
Patch fetch/XMLHttpRequest to fake a REST API server in the browser, based on JSON data.
Stars: ✭ 350 (+1196.3%)
Mutual labels:  mock, test
Backbone Faux Server
A framework for mocking up server-side persistence / processing for Backbone.js
Stars: ✭ 55 (+103.7%)
Mutual labels:  mock, test
stub-server
Stub server for REST APIs
Stars: ✭ 14 (-48.15%)
Mutual labels:  mock, test
Prig
Prig is a lightweight framework for test indirections in .NET Framework.
Stars: ✭ 106 (+292.59%)
Mutual labels:  mock, test
Faux Jax
NO MORE MAINTAINED: Intercept and respond to requests in the browser (AJAX) and Node.js (http(s) module)
Stars: ✭ 93 (+244.44%)
Mutual labels:  mock, test
Mockito
HTTP mocking for Rust!
Stars: ✭ 335 (+1140.74%)
Mutual labels:  mock, test
Nx Admin
👍 A magical 🐮 ⚔ vue admin,记得star
Stars: ✭ 2,497 (+9148.15%)
Mutual labels:  mock, test
zmock
zmock--http接口的mock平台
Stars: ✭ 98 (+262.96%)
Mutual labels:  mock, test
Mimic
Seamless client side mocking
Stars: ✭ 380 (+1307.41%)
Mutual labels:  mock, test
Hippolyte
HTTP Stubbing in Swift
Stars: ✭ 109 (+303.7%)
Mutual labels:  mock, test
Smocker
Smocker is a simple and efficient HTTP mock server and proxy.
Stars: ✭ 465 (+1622.22%)
Mutual labels:  mock, test
local-data-api
Data API for local, you can write unittest for AWS Aurora Serverless's Data API
Stars: ✭ 99 (+266.67%)
Mutual labels:  mock, test
jest-launchdarkly-mock
Easily unit test LaunchDarkly feature flagged components with jest
Stars: ✭ 14 (-48.15%)
Mutual labels:  mock, test
Httpmock
HTTP mocking library for Rust.
Stars: ✭ 76 (+181.48%)
Mutual labels:  mock, test
Mocktopus
Mocking framework for Rust
Stars: ✭ 179 (+562.96%)
Mutual labels:  mock, test

Build Status codecov npm version

instant-mock

instant-mock is a quick and easy web API mock server.

Installing globally

Installation via npm:

npm install -g instant-mock

Usage

mkdir mymock
cd mymock
instant-mock init
instant-mock

You can open http://localhost:3000 to view the instant-mock web console.

All mock API is mounted on http://localhost:3000/mock. Please try GET to http://localhost:3000/mock/users by curl or web browser. It is sample mock API created by instant-mock init.

Configuration

Servce configuration is wrote on server.yml

http:
  host: localhost
  port: 3000

socket:
  host: localhost
  port: 3010

Creating your mocks

API definition

You can create mock definition file to mock directory. Mock API URL is auto generated by directory path. mock/api-name/@METHOD is mapped to METHOD: http://localhost:3000/mock/api-name METHOD can use get/post/put/patch/delete.

If you need route parameters, can use PARAM directory. mock/api-name/$id/@get is mapped to GET: http://localhost:3000/mock/api-name/:id

Request parser

Request for mock is parsed by user definition parser file. User definition parser file name start with "parser-" and format is yaml or js.

Try create a parser file below, and access to http://localhost:3000/mock/books after restart the instant-mock.

/mock/books/@get/parser-default.yml:

status: 200                   # Response status code.
headers:                      # Response headers.
  Content-Type: application/text
rawBody: 'test body'          # Response body.

Define the response body to other file

You can define response body to a any file.

./mock/books/@get/body.json:

{
  "key": "value"
}

./mock/books/@get/parser-default.yml:

status: 200
headers:
  Content-Type: application/json
body: 'body.json'    # Response body file.

Change a reponse by request

Parser file can define multiple resonse for switing by request. Define request parsing rule to if, and response to then.

Try create a parser file below, and access to http://localhost:3000/mock/books/:id after restart the instant-mock. If :id is "1" then response body is "user 1", and if it is "3" then response is 404.

./mock/books/$id/@get/parser-default.yml:

- if:
    params:
      id: 1
  then:
    rawBody: 'book 1'

- if:
    params:
      id: 2
  then:
    rawBody: 'book 2'

- then:
    status: 404

if is can use params/query/body, and it is "and" condition.

  • params: Route parameter.
  • query: Query string parameter.
  • body: Parsed json body parameter.

Advanced parser

YAML format parser is support simple rule only. Use a js parser if you need more advanced rules.

./mock/shelves/:id/@get/parser-default.js:

exports.default = function (req) {
  return {
    status: 200,
    headers: {
      'content-type': 'application/text',
    },
    rawBody: 'your book is ' + req.params.id,
  };
};

Web console

You can open http://localhost:3000 to view the instant-mock web console. Web console can change parser, and show mock api access logs.

Web console

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].