Simple Dynamic Mock API 💎

A simple mock API using Node.js with Express written in Typescript.

Requirements

Getting Started

Clone the repository, install the dependencies.

$ git clone https://github.com/MateusVT/Simple-Dynamic-Mock-API.git <application-name>

$ cd <application-name>

Start the application.

$ yarn install

$ yarn build

$ yarn start # For production

$ yarn start:dev # For development

OR

$ npm install

$ npm build

$ npm start 

Using Docker

Install dependencies and run the application locally.

$ docker build -t dynamic-mock .

$ docker run -p 3000:3000 dynamic-mock:latest

View logs of the container.

$ docker ps

$ docker logs <CONTAINER_ID> -f

To stop the services.

$ docker stop <CONTAINER_ID>

Listing Routes

Usage

By default dynamic-mock will run at localhost:3000.

e.g.

GET localhost:3000/ // Returns server infos.
GET localhost:3000/routes // Returns all routes currently available

Registry a new route

In order to create a new route on the API you have to submit a POST request with the following body:

e.g.

POST localhost:3000/new-route // Create a new route
// JSON File
{
    "url": "/clients",
    "method": "get",
    "httpStatus": 200,
    "data": [
        {
            "clientId": 1,
            "value": 100
        },
        {
            "clientId": 2,
            "value": 200
        }
    ],
    "searchKey": "clientId" // Is optional and can be defined as `*` that means all.
}