0.9.7 • Published 6 years ago

apimocka v0.9.7

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

Travis CI Build Status David Dependancy Status npm package npm package

Introduction

APImocka helps you create a quick hosted API server populated with mock data using the faker API.

This has many uses, including, but not limited to, quick prototyping, tests and/or simultaneously developing UI and backend API.

Features

  • Authenticate with the APImocka server.
  • deploy/delete mocks.
  • Run local version of mocks.

Table Of Content

Getting Started

Installation

# via npm
npm install -g apimocka
# via yarn
yarn global add apimocka

Authenticate

# register an account
apimocka register

#...
# login to your account
apimocka login

Create a Simple Mock config file

{
    "total": 5,
    "name": "trial",
    "routes": {
        "users": {
            "fullname": "name.firstName name.lastName",
            "avatar": "internet.avatar",
            "username": "internet.userName",
            "password": "internet.password"
        }
    }
}

save file as trialMock.json

To learn more about customizing your mock config file, check here

Deploy mock

apimocka deploy path/to/trialMock.json

Mock API

After creating a new mock, you get a personalized URL in the format:

https://mockd.co/{mockId}

Mock requests

All requests made to the mockd.co server must have the content-type header set to application/json

Path (https://mockd.co/{projectId})Allowed Request typeDescription
/GETfetches all mock information
/{route}GETfetches all data in specified route
POSTAdds new data to route
/{route}/{id}GETFetches data in specified index
PUTReplaces any specified field with new data
DELETEDelete specified index and all it's child contents
/{route}/verifyPOSTPass any object and verify if any match exists in specified route

Mock Configuration

A mock configuration file is used to specify mock settings, routes structure, and total number of data to mock for each route.

The mock data is generated using the faker API

Format: JSON or YAML

Sample

A simple configuration file looks like:

JSON format:

{
    "total": 5,
    "name": "trial",
    "routes": {
        "users": {
            "fullname": "name.firstName name.lastName",
            "avatar": "internet.avatar",
            "username": "internet.userName",
            "password": "internet.password"
        }
    }
}

YAML format:

---
total: 5
name: trial
routes:
  users:
    fullname: name.firstName name.lastName
    avatar: internet.avatar
    username: internet.userName
    password: internet.password

CLI Commands

Administrative commands

CommandDescription
registerCreate a new APImocka account
loginAuthenticate to your APImocka account
listShow all your available mocks
deploy configFileCreate a new mock from config file
delete mockIdDelete an existing mock

Localization

CommandDescription
localize mockIdRun a local version of existing mock
0.9.7

6 years ago

0.9.6

6 years ago

0.9.5

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago