Menu

Home

Eric K.

Apimock

Apimock is a small tool written in Java to mock api's in development.
This occurs when api is not ready or when you want to test diffent scenarios.

If you are using Windows you can run it by double clicking the file apimock.bat
or on terminal run :\
apimock.bat

For linux users you can use the following command\
sh apimock.sh

How to add the mocks

Open the file mocks.json and add an URL and the response to return when your URL called.

config.json structure

{
    "paths":[
        {
            "path":"api/exemples",  
            "contentType":"application/json",
            "fileAbsolutePath":"mocks/exemples.json",
            "responseHttpStatus": 400
        },
        {
            "path":"api/notes",
            "contentType":"application/xml",
            "fileAbsolutePath":"mocks/notes.xml",
            "responseHttpStatus": 200,
            "responseHeaders":[
                {
                    "name" : "header1",
                    "value" : "header1Value"
                },
                {
                    "name" : "header2",
                    "value" : "header2Value"
                }
            ],
            "responseCookies":[
                {
                    "name" : "cookie1",
                    "value" : "cookie1Value"
                },
                {
                    "name" : "cookie2",
                    "value" : "cookie2Value"
                }
            ]
        }
    ]
}

This means when you call http://localhost:8080/api/notes you'll get in response
the content of the file mocks\notes.xml and Content-type header set to application/xml. \
You will override the content of mocks.json, you stay have an orginal copy in mocks.example.json. \
You can change the port number on command line(apimock.bat or apimock.sh)
contentType
Response body content type

fileAbsolutePath
File where to ready the response body

responseHttpStatus
Http status that you wish the api to return, default value is 200.
You can test Authorization by setting it to 203 or 400 for BadRequest

responseHeaders
Headers you with server to return.

responseCookies
Cookies you with server to return.

You can find the logs in apimock.log file.

NB:
Request methods are ignored, using GET, POST, DELETE results in same response.
Ctrl + C to stop servers, closing the window does not free the port.
* You can set only the fields you wish to use.

content\
- apimock.jar --> application
- apimock.log --> logs, the file is cleared when application starts
- mocks/notes --> example of response content
- apimock.bat --> launches application for windows users
- apimock.sh --> launches application for linux users
- config.example.json --> example of how to config ports, paths and mocks
- config.json --> Active configuration of ports, paths and mocks
- README.md --> me :) !!