Generate Mock APIs
In order to generate Mock APIs, we want to ensure that:
Request responses can be recorded instead of hard-coding
Request responses can be refreshed without having to manually update contracts
Minimize Hard-Coding
Recording
Stoobly lets you easily create mock APIs by recording HTTP traffic. To record traffic, Stoobly acts as a proxy between a client and server and intercepts traffic that passes through.
In comparison, to generate HTTP request mocks without recording:
Use a client driver (e.g. curl, browser) to send a HTTP request
Copy and paste the HTTP response into a mock tool or library
Repeat for different request variations and/or endpoints
We can see that this process quickly becomes difficult to scale. As either the number of HTTP request variations increase or as new endpoints are added, we have to keep manually adding responses to our mocks.
With recording, the process looks like:
Configure a client driver (e.g. curl, browser) to proxy requests to Stoobly
Send a HTTP request and let Stoobly record it for you
Repeat for as many HTTP requests as you want
(Optional) Stoobly enables configuration of which requests gets recorded and enables rewriting parts of a request.
Mocking
Stoobly comes out of the box with comprehensive request and response matching that should cover most use-cases without explicitly stating the match requirements. By default, Stoobly matches a HTTP request by looking for exact match of path, query params and body. If needed, match rules can be configured to relax or tighten matching requirements.
In comparison, to configure how HTTP requests are matched when mocking manually:
Specify a exact path to match or use regex for pattern matching
Repeat for every HTTP request that the mock API needs to support
An additional difficultly to highlight here is that matching bodies is often not possible. This is because the body would first have to be pared based on the specified content type.
With Stoobly mocking, the process looks like:
Requests will be matched without additional configuration
(Optional) Stoobly enables configuring how a request gets matched. Matching against query params, body or headers can be either relaxed or tightened.
Scale Maintenance
A mock API works great from the time it is created to when it comes time for maintenance. Stoobly enables you to replay recorded requests and either overwrite the existing request response or alternatively, create a new version of the request.
In comparison, to update a HTTP response mock manually:
Determine which mocks need updating
Use a client driver to resend a HTTP request
Copy and paste the updated response
Repeat for other mocks that need updating
While to above flow may not mirror exactly how mocks are always updated (sometimes we directly modify the mock), it serves to illustrates the difficutly in:
Understanding which mocks need updating
Understanding what a new correct version of the mock looks like
This problem gets even worse when we want to update a sequence of requests that have a relationship with each other (e.g. creating, reading, and deleting a resource are connected by the resource ID).
With Stoobly mocking, the process looks like:
Determine which requests or scenarios need updating
Replay and record the requests or scenarios
Last updated