Mocking HTTP requests is a vital part of any testing regiment. The ability to test a wide range of possible situations, realities and use cases is extremely important, and it presents a great opportunity to really future proof your API. What tool you use to implement this does matter – your tool should be able to mock common API interactions and HTTP request flows, and most importantly, it should be appropriate to your given code base and situation.

Today, we’re going to look at 10 tools for mocking HTTP requests. These tools each offer something a little different from the others and present a variety of interesting build options and implementations.

1 – Nock

Nock is an HTTPS library designed to replicate and mock servers and expectations in Node.js. Functionally, Nock does this by overriding both the http.request and http.ClientRequest functions, intercepting requests and responding with a specific mocked response through the use of Interceptors.

Interceptors are addressed in the order they appear on a list, meaning that you can create multiple interceptors that result in different responses to two or more calls. This is especially useful if you’re testing mocked failures or routing, as you can mimic complex server functionality relatively seamlessly.

It should also be noted that request paths can be a string, a filter function, or a RegExp. This means you can use any HTTP verb to mimic a request across a multiplicity of different request paths depending upon your testing case with high complexity and variability.

2 – MockServer

MockServer (and its counterpart service MockServer Proxy) is a multifaceted tool that comes in a variety of builds. It’s available as a Netty web server, a Docker container, a Maven plugin, an npm plugin, and a Grunt plugin. There’s a ton of great options that can be leveraged for a variety of environments. This already makes it a pretty compelling tool given that you can plug it into just about anything you’re running, but its wide range of functionality is the core compelling argument.

MockServer responds to requests based upon a series of configured expectations, wth support for mocked responses, request forward, callback generation, invalid response/connection closure, test assertion, and log retrieval. For this reason, MockServer is both well-defined and configurable, making it a great option for most use cases.

3 – Beeceptor

Beeceptor is a great tool largely because it requires absolutely no code in order to utilize it. Beeceptor is a free online tool for mocking a REST API interaction using any HTTP request. You can customize your responses to simulate pretty much any response or failure situation. Beeceptor also offers some great functionality to simulate latency on downstream APIs – you can both simulate transmit latency and timeouts, which is a great use case for many APIs and often missed during testing.

Beeceptor also has excellent support for A/B testing. This is another use case that is often missed by other mocking options, or if it is supported, it requires redeployment or ad hoc testing configurations. Beeceptor supports A/B testing without the need to redeploy or utilize multiple testing environments, which might seem like a small benefit, but in actuality leads to a much cleaner, leaner, and efficient testing apparatus.

4 – Mockoon

Mockoon departs from the other solutions on this list in that it’s neither a web solution nor a code solution. Mockoon is a downloadable program that mocks an unlimited number of environments and routes – Mockoon makes a point to note that these can be run in parallel, and its strong import/export system ensures that enterprise, multi-path, multi-environment situations can be adequately supported.

Aside from its novel deployment method, Mockoon offers a wide range of support for common server variables. Self-signed certificates, rules-triggered responses, latency simulation, and more function to replicate common server conditions while allowing flexible enough configuration options to mock almost any system. Noteworthy is the fact that you don’t need to register or deploy to the cloud – everything is done locally.

5 – Mocky.io

Mocky is an incredibly simple and super lightweight testing implementation. Mocky is entirely a web app, meaning that everything is generated and managed remotely. This does mean that Mocky grants you significantly less control compared to solutions that focus more on local systems, but this also means the application is simpler and cleaner.

Mocky has great support for a ton of common functionality, but because it is a web app, you have to add this functionality in URL form. For instance, adding ?callback=myfunction enables jsonp; adding ?mocky-delay=100ms allows you to add delays. This sort of functionality still delivers quite a lot of value, but it does point to the relative simplicity of the app – if exceeding granular control is something that is desired, Mocky might not be the first option. For simple interactions, however, Mocky is a great choice.

6 – Mockable.io

Mockable was designed from the ground up to be simple and easy to use, and it shows – everything Mockable does and presents is slick and intuitive. Because of this ethos to design, it’s incredibly fast to get from nothing to a mock server.

One thing to note is that Mockable seems to have bought it on the idea of offering the solution at hand primarily to enterprise users. The ability to organize the mocks in a “Domain,” a collection where multiple users can interact with sub-domains and mocks, as well as the team tools built on the Domains system suggests that this is principally targeted towards that particular segment.

That being said, it’s still a very good choice and offers a great range of features and extensions to do what it does.

7 – Stoplight

Stoplight is all about the quick creation of mock servers and visualization of the APIs that interact with them. Through a variety of tools, Stoplight offers excellent virtualization, automatic validation against OpenAPI documentation, and high support for configurable and dynamic content generation.

Stoplight is also built upon Prism, an open-source HTTP mock server offering – being open source is a huge benefit, and the fact that it also supports Swagger is definitely another pro.

It should also be mentioned that Stoplight is really a series of offerings rather that a singular option. For regular users, this includes both Stoplight Studio (the actual mocking implementation) and Stoplight Docs, a powerful documentation engine that generates documentation from OpenAPI v2/v3. For enterprise users, Stoplight Hubs is a deployable documentation hub for custom branded documentation, and Stoplight Enterprise is its standard offerings beefed up for enterprise implementation.

8 – Postman Mock Server

Mock Servers in Postman are tied directly to the Postman app, and for that reason, are a suggestion for a very particular use case. Postman is a great testing solution, and their mocking system is equally great, but the fact that it’s tied to both a Postman account and a defined collection means that using only the Mocking system means that you are buying into an incomplete testing experience. You can create a mock server without an existing collection, but in this case it’s kind of like buying an entire sewing kit for a single needle.

That may not be a deal-breaker, of course – Postman is an excellent testing system and is in relatively common use by many API developers. Still, the fact that the mocking system is but a single aspect of a much larger testing apparatus may deter some users. There’s also the fact that it’s not completely free – Postman allows a limited number of free mock calls, but users engaging in heavy development may quickly find themselves exhausting this limited number.

9 – Wiremock

Wiremock bills itself as a “simulator for HTTP-based APIs” – in essence, it’s a virtualization tool for mocking, but the product seems aligned towards the idea of holistic simulation. Mocklab takes this a step further, offering mocking through a web UI. The main selling point for Wiremock is the flexible deployment – it boasts deployment through a variety of implementations, and “drop-in replacement […] with a single line of code”, making it quite flexible to a number of solutions.

Perhaps the two strongest value propositions for Wiremock is its request matching and traffic capture. Matching can be done across URLs, methods, headers, cookies, and bodies using JSON and XML, as well as a variety of other options. This, paired with the relatively robust record and playback functions that allow traffic capture and analysis means that mock testing can be done pretty robustly.

10 – Mockserver

Mockserver is a library that utilizes mock files in order to serve realistic mock responses. It does this by creating local mock files that serve content as if they were part of a real API localized on port 9001. Because of the relatively clean and quick implementation, Mockserver boasts that API mocking can be created in “a matter of seconds” – more to the point, because such a system is super lightweight, it also means that it’s highly adaptable across a wide range of options.

For this reason, Mockserver is a great option if quick testing is needed with relative immediacy. Mockserver is verbose, supports custom headers, has a built-in response delay simulation scheme, and offers a wide range of additional options to mimic standard testing environments.

Conclusion

As with any sort of list like this, your choices are really dictated by your current situation. Any option delineated here is going to do the job of mocking HTTP requests with relative ease and efficiency, though the mode of execution and the result of said execution may change from implementation to implementation. Nonetheless, these options are all wonderful in their given use case and can be leveraged to provide a fast, clean, and intuitive environment for testing and iterative development.

What do you think about the options presented here? Are we missing any major mocking options? Let us know in the comments below.

Kristopher Sandoval

Kristopher is a web developer and author who writes on security and business. He has been writing articles for Nordic APIs since 2015.