Introduction

Mock API Server is an easy way to create dummy/mock RESTful APIs.

Thank you for your interest in Mock API server. We really appreciate it and are ready to help you!

This guide will help you get started with using Mock API server. It's very easy to build a mock RESTful API using Mock API Server. A dummy or mock API is a static API that returns fixed response. While defining your RESTful APIs in Mock API Server, you can use values in header, URL and request body to generate your response.

Features

Before getting started, let us get familiar with salient features of the Mock API Server.

Mock API Server is design to be easy to use and supports common features for building a mock API.

  • Supports all HTTP methods - using Mock API Server you can build RESTful API for any of the HTTP methods - GET, POST, PUT, PATCH, DELETE etc.
  • Supports both XML and JSON response - Mock API Server uses ACCEPT header of incoming request for content negotiation. A header value of application/xml will result in XML response, and that of application/json will result in JSON response. If the header value is not specified, Mock API Server defaults to JSON response.
  • Dynamic Response - Mock API Server allows creation of dynamic response by using the values from input request. The values from request header, URL query parameters and request body can be used to generate output response of an API.

Getting Started

Mock API Server uses Github to fetch JSON response based on api URL. An api URL is mapped to the folders in the Github repository and a JSON file with name matching to HTTP method us returned.

  1. Create a public Github repository. For example mock-api-server-demo.
  2. Create a folder structure to mimic your api path. Eg. /api/persons.
  3. For supporting JSON response, add separate JSON files for each HTTP method that you want to support at this api path. Example, for GET method add get.json, for POST method add post.json and so on. Make sure the file names are in lower case.
  4. If you want to support XML response, create XML files for each HTML methods.
  5. That's it now you can access you dummy API using path https://dummyapi.actigence.com/api/{github-account}/{github-repo}/{github-branch}/api/persons.

API with Path Variables

Mock API Server treats path variables as simple folders in your Github repository. Example, if you want to create an api with path api/persons/100, simply create a folder path api/persons/100 in your repository and add the JSON response files there.

API with Query Parameters

Mock API Server works by mapping your query parameters to a repository folder. It uses following rules to map query parameters to the destination Github folder.

  1. It sorts all your query parameters by name in alphabetical orders. Eg. name=James&age=32 becomes age=32&name=James , where age and name are sorted in canonical order.
  2. Next all the special characters are replaces by hyphen (-). Continuing from above example, age=32&name=James becomes age-32-name-James , here all the special characters line & and = have been replaced by - .
  3. Finally, response is read from the above folder. Eg. /api/persons/search?name=James&age=32 will try to fetch response content from /api/person/search/age-32-name-James , folder of your Github repository.
  4. If expected folder name is not found in the Github repository. The Mock API Server tries to pull the contents from parent folder. Example, if /api/person/search/age-32-name-James is not found, then Mock API Server tries to fetch content from /api/person/search folder.

Usage Examples

You can visit our Github demo repository to see all the examples.

Some of the example scenarios are listed in the table below.

Desired API Path Http Method Repository Path Mock API Server URL
/api/persons GET /api/persons/get.json Click to see in action.
/api/persons POST /api/persons/post.json See our Postman Collection
/api/persons/10000 GET /api/persons/10000/get.json Click to see in action.
/api/persons/search?name=victor GET /api/persons/search/name-victor/get.json Click to see in action.
/api/persons/search?name=invalid GET /api/persons/search/get.json Click to see in action.

Postman Collection

All the examples described in this documentation are also available as a sample Postman collection.

To use the Postman collection, you will need to install Postman API Client and import both example and environment files. After that you will be able to execute the examples through your Postman installation.