Git Product home page Git Product logo

starworld-mock-api's Introduction

starworld-mock-api

A server that responds with mock data.

Development

Run the linter:

npm run watch

Integration Tests

NOTE: These tests probably only work on macos, since using gtimeout and greadlink in the wait-for-it.sh script.

NOTE: If running on macos, you will need coreutils installed.

brew install coreutils

Run tests:

npm run test

Usage

This command starts up a service running on a specified port. The command is added to npm's bin as starworld-mock-api.

Usage: starworld-mock-api -p <num>

Options:
  --version  Show version number      [boolean]
  -h         Show help                [boolean]
  -p         The port to listen on.   [required]

The service exposes several endpoints.

/_starworld/register

Register an endpoint with the server. After registering, if this endpoint is queried, it will respond with the data provided in the request. The query part of the URL will be ignored when matching the requested URL (e.g. if your endpoint is '/test', it will match '/test?blah=1'). However, the endpoint param provided when registering will not be altered, so if you include a query in it, it likley won't match any requests.

Method: POST

Content Type: application/json

Parameters:

  • endpoint (string, required) The path of the endpoint you want to register (e.g. /user/messages)
  • method (string, optional, default: GET) The request method to respond to.
  • status (int, optional, default: 200) The status to respond with when the endpoint is queried
  • headers (object, optional, default: {'Content-type': 'application/json'}) Any response headers to send.
  • respondRaw (boolean, optional, default: false) By default, the response will be sent as JSON. Set this to true and the response body will be returned exactly as provided.
  • body (any, required) The response body. By default will send this as JSON string. See respondRaw to change this behavior.
  • responses (array[object], optional) Instead of sending status, headers, responseRaw and body, you can send an array of objects with those keys. Each subsequent call to the endpoint will respond with a value from that array. After the array is exhausted, all subsequent calls will response with the last value from the array.

Result:

Status: 200, 500 (on error)

/_starworld/clear

Clear one ore all endpoints.

Method: POST

Content Type: application/json

Parameters:

  • endpoint (string, optional) The endpoint to clear. If not provided, will clear all endpoints
  • method (string, optional, default: GET) The method to clear.

Result:

Status: 200, 500 (on error)

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.