Code Monkey home page Code Monkey logo

mock-rest-api-service's Introduction

Mock REST API Service

Test how well your app handles errors returned by RESTful API Services.

This basic NodeJs app allows you to force any Response Code with the response delay (in seconds) of your choosing.

Shout Outs:

This exists solely because Test Insane took down their RestFul Test Endpoints tool, upon which I'd grown quite dependent. This is a crude approximation of that service.

Installation

Dependencies: this was written under Node version v4.4.2 and npm version 2.15.0.

After downloading/cloning this repo install its dependencies from within a terminal:

$ npm install

Launch The App

$ node index
Listening on port 3080

Start server on a different port

$ node index 8089
Listening on port 8089

Simple Example Usage

Test that the service is running as expected by call the status endpoint via curl or in your web browser:

$ curl localhost:3080/status/302/6

Returns response code 302 after a 6 second delay.

Server Output

The server echoes each request received. (TODO: include timestamp)

$ node index
Listening on port 3080
Request => (Response Code: 301, Delay: 0 seconds)

Endpoints Documentation

  • Method GET: Get endpoints responds with HTTP Status Code and empty content.
  • Method POST: Post endpoints responds with HTTP Status Code and data sent by the client as part of request. (Not available yet)

Detailed individual endpoint information is given bellow.

Note: Where applicable delay value must be between 0 and 600, otherwise response returns immediately. "0" is default, meaning no delay.

--

GET /list

  • Returns JSON object with complete list of allowed codes
  • Usage: http://localhost:3080/list
  • Method: GET

--

GET /random

  • Gets random HTTP Status Code
  • Usage: http://localhost:3080/random/{delay}
  • Method: GET
URL Params
Name Type Description
delay integer (Optional) Delay in seconds before response is sent.
Example 1:
  • Request: /random/5
  • Code: 200 OK
  • Content:
Example 2:
  • Request: /random
  • Code: 401 UNAUTHORIZED
  • Content:

--

GET /status

  • Gets specified HTTP Status Code
  • Usage: http://localhost:3080/status/{code}/{delay}
  • Method: GET
URL Params
Name Type Description
code integer (Required) HTTP Status Code to return.
delay integer (Optional) Delay in seconds before response is sent.
Example 1:
  • Request: /status/200
  • Code: 200 OK
  • Content:
Example 2:
  • Request: /status/401/3
  • Code: 401 UNAUTHORIZED
  • Content:

mock-rest-api-service's People

Contributors

buzcarter avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

lahela3

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.