May 3, 2018

Mocking a REST API using mocktastic

A short how-to on mocking a REST API using mocktastic.

Never heard of Mocktastic before? Well, Mocktastic is a cross platform, downloadable, GUI desktop application, which allows you to easily mock up any REST API without having to write a single line of code. Anybody can create a mock API server, and then share it with their team, so the entire team can use it. Click here to know more!
Mocking a REST API using mocktastic

While we have designed mocktastic to have a very intuitive UX, we understand that it might not be so intuitive for everyone. So here's a short how-to on mocking and running a mock server using mocktastic.

Note: This how-to is split up into two parts. In this first part, we will cover creating a new mock API. In the second part, we will see how to run the mock API, and extract different types of responses from it.

Let's create a super simple mock REST API. Our REST API has a single endpoint, and upon hitting it, it returns either a success message, or an error message.

To implement this we'll create a mock server, having the following endpoint.

GET /endpoint which responds with one of two responses:

  • 200 OK - JSON success message in body
  • 400 Error - JSON error message in body

To mock this API, you will need to create a server, an endpoint and two responses for that endpoint. Here's how you do that:

Create a Server:
  • Open Mocktastic.
  • Click 'Add New Server' in the sidebar [1].
  • A new tab called 'New Server' will open up.
  • Enter a name for your server in the 'Server Name' field [2].
  • Click the 'Create Server' button [3].
Create an Endpoint
  • Click the 'Add New Endpoint' button in your newly created server. (You might have to scroll down a bit to find it.) [1]
  • Ensure that the method selected is 'GET' [2].
  • Enter the path for the endpoint as '/endpoint' in the Route field [3].
  • Click the 'Create Endpoint' button [4].
Create the Responses
  • Click the 'Add New Response' button in your newly created endpoint. (You might have to scroll down a bit to find it.) [1]
  • Select '200 OK' in the 'Status Code' field [2].
  • Enter a name for this response in the 'Name' field. This is optional, but it helps you identify your responses easily [3].
  • Enter the following JSON message in the 'Body' field [4].
    "success": true,
    "message": "Congratulations! You've made a successful request."
  • Click the 'Create Response' button [5].

Repeat the above steps to add another response to the same endpoint.

This time set the 'Status Code' as 400, and use the following error JSON for the 'Body'.

    "success": false,
    "message": "Looks like you did something wrong :("

The end result should look something like this:

That's it. You have successfully created your first mock API!

Update: Part 2 of this how-to, on running your mock API, is now available. Click here to read it.