Mock API Server now supports XML response type.
HTTPs `ACCEPT` header is used for content negotiation.
This repository contains examples on how to use Mock API Server to generate dummy RESTful apis.
Mock API Server is a simple way to create mock RESTful APIs. It allows you to define a JSON response for an API URL. It supports all the HTTP methods and you can also define different responses based on query params.
- Creating Your First Mock API
- Using Path Variables In Mock APIs
- Using Query Params in Mock APIs
- Examples In This Repo
- Postman Collection
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.
- Create a public Github repository. For example
mock-api-server-demo
. - Create a folder structure to mimic your api path. Eg.
/api/persons
. - 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 addpost.json
and so on. Make sure the file names are in lower case. - 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.
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.
Mock API Server converts your query parameters to a repository folder, using following rules:
- Sort the parameters.
- Replaces all special characters with
-
(hyphen). - Merge all the parameters into a single folder name.
Example, an API path like /api/persons/search?name=victor&country=CA
will result in folder structure as /api/persons/search/country-US-name-victor
.
You should create corresponding folder structure in your Github repository and add JSON files there.
If the folder structure with Query parameters is not found, Mock API Server will use URL path as backup folder structure.
Example, with API path like /api/persons/search?name=victor&country=CA
Mock API Server will first search for JSON file in folder /api/persons/search/country-US-name-victor
. If no matching JSOON file is found, then it will search in folder /api/persons/search
.
Desired API Path | Http Method | Repository Path | Mock API Server URL |
---|---|---|---|
/api/persons | GET | /api/persons/get.json | Click To Open |
/api/persons | POST | /api/persons/post.json | Use Postman Collection |
/api/persons/10000 | GET | /api/persons/10000/get.json | Click To Open |
/api/persons/search?name=victor | GET | /api/persons/search/name-victor/get.json | Click To Open |
/api/persons/search?name=invalid | GET | /api/persons/search/get.json | Click To Open |
This repository contains a Postman collection, that allows you to execute examples in this repository against Mock API Server.
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.