Developing complex, interactive web applications can be a significant undertaking fraught with potential pitfalls and challenges. Fortunately, developers have a significant number of tools to help them avoid many pitfalls and address common challenges. From robust IDEs and web application frameworks to unit testing libraries and continuous integration software, just about every step of the development lifecycle is covered. Building API-reliant applications, however, can add a wrinkle that common tools aren't prepared for. For instance, API access is one of the biggest challenges developers face when developing these applications. In many cases, an API is being developed concurrently and thus isn't available. In others, there may be environment restrictions that make it difficult or impossible for applications under development to make HTTP calls to the public internet. The good news is that a growing number of tools will allow developers to mock web services, helping developers of applications that depend on APIs to speed development and improve quality by facilitating functional testing. These tools come in several flavors: web-based solutions, servers and desktop software.
Apiary is a start-to-finish solution for designing, documenting and mocking new APIs. Using the company's API Blueprint, an open-source, markdown-based "web API language," Apiary's users can define their endpoints, share the resulting API design with teammates and other collaborators, and have API documentation generated automatically along the way. Once an API design is ready, Apiary creates a functioning mock that allows developers or prospective users to work with the API before it's fully implemented. Given the number of applications that rely on an external web service, it's no surprise that there's a SaaS offering, Mockable, focused exclusively on mocking web services. Mockable supports both SOAP and REST APIs, and, backing up its "Create one mock in three seconds" claim, gives users the ability to create a functioning mock automatically using a WDSL or API documentation from a variety of sources, including Apigee and Swagger. Mockable users can create and manage their mocks using an API, and should it be necessary, mocks can be made available through a user's own domain name. The service is currently operating in a free preview mode but Mockable says it will offer paid plans in the future.
MockServer is a robust mock HTTP server. It can be configured to respond to requests based on a variety of criteria, including headers and cookies, and can be configured to issue delayed or repeat responses. In addition to serving as a pure mock server, MockServer can be used as a proxy for the purpose of logging and debugging requests and responses. MockServer is a Java application and can be deployed in a number of ways, including as a standalone web server or Maven plugin. Mock API Server is a mock API server designed specifically for simulating a REST web service. Built on the Sinatra Ruby framework and MongoDB, it features a web-based interface through which mock APIs can be created and managed. The aptly-named Canned is a Node.js server that allows developers to quickly mock a REST API by mapping requests to static files containing response content. Nested endpoints, variable responses based on query string parameters, custom HTTP status codes and CORS headers are all supported. Canned can be installed using Node.js's package manager, npm. Another Node.js solution worth a look is Dyson. Like Canned, it is available through npm and features nested endpoints, custom status codes and CORS headers. In addition, it adds a number of potentially useful features, such as a random data and image generator, a dummy image generator, the ability to combine responses for nested endpoints, and an option to proxy requests to real web services. Generic HTTP Stub is a versatile Java-based server that itself allows users to create and manage mock responses using a built-in API. Handy debugging features include request logging, as well as the ability to set a response delay for requests. Currently, Generic HTTP Stub offers a sample Ruby client, but its creator promises more clients for other languages in the future. Last but not least, WireMock is a mocking solution that can be used as a Java library or run as a stand-alone server. Like Generic HTTP Stub, it can be managed through its own API. One of WireMock's most notable features is its record and playback functionality, which allows responses from real web services to be recorded and used as mock responses.
In cases where a web-based solution isn't viable or setting up a mock server isn't convenient, desktop software may be attractive. Mule Studio is an Eclipse-based IDE that supports the creation of mock web services through APIkit, a plugin that Mule Studio's creator, MuleSoft, released last year. APIkit uses RESTful API Modeling Language (RAML), an open, vendor-neutral specification for describing REST APIs, that can be created, documented and tested using a number of open-source tools also developed by MuleSoft. (Disclosure: MuleSoft is the parent company of ProgrammableWeb.com.) For developers already using an IDE or who prefer a non-IDE-based solution, SoapUI is a dedicated functional testing application available on Windows, Mac OS X and Linux. It comes in two flavors, free and paid. The free version is open-source, while the closed-source pro version offers additional features and access to support. Both versions allow developers to build mock web services that can be used to run functional tests for their applications. Using an existing Web Services Description Language (WSDL), SoapUI can create a mock SOAP web service with all of the real web service's operations. Developers can mock static responses, or use SoapUI's scripting capabilities to create dynamic responses. Once in place, the mock web service can be run from within SoapUI or exported as a WAR file for deployment as a Java servlet. While SoapUI does support REST APIs, the software's mocking functionality is currently focused on SOAP web services. Fortunately, with some tweaking, it is possible to mock REST web services as well.