Test the API Specification
It’s time to test your API specification to prototype the implementation. In this step, you activate the API Mocking Service. The mocking service enables you to simulate the behavior of an API specification. The mocking service provides a test link to an API. The mocking service returns the responses (both HTTP status codes and example payloads) that are defined in your API specification. These responses are valuable for testing or exploring how your API behaves.
Navigate to the QuickStart-Store API in the Design Center that you built in the last unit. On the right-hand side of the screen, click the Mocking Service Configuration icon as shown in the following screenshot.
Then, in the Service Settings, click the slider in the Make Public section.
After the Mocking Service is made public, the slider changes to blue with a check mark. You see a new parameter called Public link with a copy button for copying that public link to your clipboard. Click Copy.
Next, we’ll guide you through calling the API two separate times; once using the interactivity that’s built into the documentation and once from outside the Anypoint Platform.
Send a Request to Mocking Service
Now that the mocking service is public, click the Documentation icon on the right-hand side of the screen as shown in the following screenshot.
The Documentation pane includes the API summary where you can try a request and see the response.
- Click GET following /products/{productId} to view the endpoint details.
- Click Try it.
- To test the request, enter the following values.
- productId*:
2
- Credentials User name:
mulesoft
- Credentials Password:
mulesoft
- Click Send.
Scroll the pane a bit more and you see that the mocking service returned a 200 response with the example body.
The same API call can also be tested outside of the Anypoint Platform by performing a similar request with another web client, such as curl using the following.
curl -X GET {{yourMockingServiceUrl}}/products/2 -u mulesoft:mulesoft
For the mocking service URL, use the URL that you copied when you activated the mocking service earlier (without the curly braces shown in the previous example).
Note: Since you’re using the mocking service, changing the product number at the end of the URL will return the same sample response.
The mocking service URL can be shared with other stakeholders and can be used for testing during the design phase.