0.1.10 • Published 6 years ago

restimpy v0.1.10

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

Restimpy

A simple and fast restful mock server based on express. Restimpy allows you to connect via http and https. It can mock any kind of respond and it is CORS enabled.

Prerequisites

  • nodejs and npm
  • install dependencies: npm i

Restimpy api

  • restimpy start starts the http server by default on port 8080
  • restimpy start --http 8900 starts the http server on port 8900
  • restimpy start --https 8443 starts http server on default port and also starts https server on port 8443, the default port for https is 8443
  • restimpy start --cors starts http server on default port with cors enabled, cors is disabled by default. Cors option needs to be at the beginning of options
  • restimpy start --cors --http 8080 --https 8443 starts http and https servers on the ports provided and enables cors

Starting the Restimpy mock server

  • You can start the server using the package.json script section and creating a script to start the server like this:
    script:{
        mocks:"restimpy start"
    }
  • Or directly calling the Restimpy mock server on in your project like this (from the command line): node_modules/.bin/restimpy start

Using the Restimpy HTTPS mock server

  • In your project's root directory, under the Restimpy folder place your certificates inside the certificates directory. If it does not exits, create one and name it certificates.
  • Start Restimpy mock server (if certificates are not present, the Restimpy mock server for https will not start)

Creating a Restimpy mock file

  • Create a javascript file and give it a name such endpoint_name.endpoint_method.status_code.js place it under PROJECT_ROOT_DIRECTORY/restimpy/routes
  • Create a mock inside the file like this:
module.exports = {
    name: 'users',
    path: '/v1/users',
    method: 'get',
    always: false,
    response: (req, res) => {
        res.json({
            result: [
                {name: 'john', title: 'programmer'},
                {name: 'steve', title: 'manager'}
            ],
            error: null
        });
    }
};
  • Access the mock using Restimpy mock server address and the mock's path. For example: http://localhost:8080/v1/users

Browsing Restimpy mock server

  • Start the Restimpy mock server
  • Point your browser to the address provided to you by Restimpy mock server when it starts. Example: http://localhost:8080

View all Restimpy mocks

  • Start the Restimpy mock server
  • Point your browser to the Restimpy home page (the address provided to you by the Restimpy mock server when it starts)
  • Click on the Get All Mocks link

View a specific Restimpy mock

  • Start the Restimpy mock server
  • Point your browser to the Restimpy home page (the address provided to you by the Restimpy mock server when it starts)
  • Once in the home page, click on the Get All Mocks and then select the id of the mock you would like to view.

Updating a Restimpy mock file

  • Stop the Restimpy mock server
  • Update the Restimpy mock file or files that you need to be updated
  • Start the Restimpy mock server again

Creating SSH Certificate

  • openssl genrsa -out key.pem
  • openssl req -new -key key.pem -out csr.pem
  • openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
  • rm csr.pem

TODO

  • Load routes folders
  • Load route object to view
  • Load routes to view
0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago