SDKs overview
Mocky provides a service for generating temporary HTTP mock endpoints, primarily accessed through its web interface or direct API calls. While Mocky does not maintain an extensive suite of official SDKs in the traditional sense, its straightforward RESTful API allows for integrations using standard HTTP client libraries available in most programming languages. The community has developed several libraries to simplify interaction with the Mocky API, abstracting the underlying HTTP requests into more idiomatic language-specific functions. These libraries generally focus on streamlining the creation and management of mock endpoints, which can be particularly useful for automated testing environments or continuous integration pipelines.
Developers can integrate Mocky into their projects by making HTTP requests directly to the Mocky API documentation or by utilizing community-contributed wrappers. The core functionality exposed through these methods includes defining HTTP status codes, custom headers, and response bodies for mock endpoints. This approach reduces the need for a dedicated backend during frontend development or when isolating services for unit and integration testing.
Official SDKs by language
Mocky's approach to SDKs differs from platforms that offer a broad range of vendor-maintained libraries. Instead, Mocky primarily relies on direct API access and community contributions for language-specific integrations. As of 2026, Mocky does not officially publish or maintain a comprehensive set of SDKs for various programming languages. The primary method for programmatic interaction is through its REST API. Developers typically use standard HTTP client libraries available in their chosen language to interact with Mocky's endpoints for creating, updating, and retrieving mock responses.
While there isn't an official SDK matrix, the underlying API is designed to be accessible via any HTTP client. This design choice allows for maximum flexibility, as developers are not bound to specific library versions or frameworks. The community has filled this gap by creating various helper libraries and wrappers, which are discussed in the Community libraries section.
The table below illustrates how one might conceptually interact with Mocky if an official SDK existed, or how community libraries often structure their interfaces:
| Language | Package/Approach | Installation Command (Conceptual) | Maturity |
|---|---|---|---|
| Python | requests library (direct API calls) |
pip install requests |
Mature (HTTP client) |
| JavaScript/Node.js | axios or fetch (direct API calls) |
npm install axios or built-in fetch |
Mature (HTTP clients) |
| Java | HttpClient (direct API calls) |
Maven/Gradle dependency for java.net.http |
Mature (HTTP client) |
| Ruby | Net::HTTP (direct API calls) |
Built-in | Mature (HTTP client) |
Installation
Since Mocky primarily supports direct API interaction and relies on community-contributed libraries, installation typically involves adding a standard HTTP client library to your project or installing a specific community wrapper. The steps below outline the general process for common programming languages.
Python
For Python, the requests library is a widely used HTTP client for making web requests. To install it, use pip:
pip install requests
JavaScript/Node.js
In JavaScript environments, you can use the built-in fetch API in browsers and recent Node.js versions, or a library like axios for more features. To install axios:
npm install axios
# or
yarn add axios
Java
For Java, the java.net.http.HttpClient is available since Java 11. For older versions or more advanced features, Apache HttpClient is a common choice. If using Maven, add the following to your pom.xml:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version> <!-- Use the latest version -->
</dependency>
For Gradle, add to your build.gradle:
implementation 'org.apache.httpcomponents:httpclient:4.5.13' <!-- Use the latest version -->
Ruby
Ruby includes Net::HTTP in its standard library for making HTTP requests, so no additional installation is typically required. For a more user-friendly interface, the httparty gem is popular:
gem install httparty
Quickstart example
This quickstart demonstrates how to create a basic mock endpoint using direct API calls via an HTTP client. The example will create a mock that returns a JSON object with a 200 status code. For more advanced configurations, refer to the Mocky API documentation.
Python Example
This Python snippet uses the requests library to create a mock endpoint:
import requests
import json
# Define the mock response content
mock_data = {
"status": 200,
"headers": {
"Content-Type": "application/json",
"X-Mocky-Header": "CustomValue"
},
"body": {
"message": "Hello from Mocky!",
"data": [1, 2, 3]
},
"latency": 100, # Optional: Add 100ms latency
"expire": "1h" # Optional: Mock expires in 1 hour
}
# Mocky API endpoint for creating new mocks
create_url = "https://www.mocky.io/api/mock"
try:
response = requests.post(create_url, json=mock_data)
response.raise_for_status() # Raise an exception for HTTP errors
mock_info = response.json()
print(f"Mock URL: {mock_info['link']}")
print(f"Admin URL: {mock_info['adminUrl']}")
except requests.exceptions.RequestException as e:
print(f"Error creating mock: {e}")
JavaScript (Node.js with Axios) Example
This Node.js example uses axios to achieve the same:
const axios = require('axios');
const mockData = {
status: 200,
headers: {
'Content-Type': 'application/json',
'X-Mocky-Header': 'CustomValue',
},
body: {
message: 'Hello from Mocky!',
data: [1, 2, 3],
},
latency: 100, // Optional: Add 100ms latency
expire: '1h', // Optional: Mock expires in 1 hour
};
const createUrl = 'https://www.mocky.io/api/mock';
axios.post(createUrl, mockData)
.then(response => {
console.log(`Mock URL: ${response.data.link}`);
console.log(`Admin URL: ${response.data.adminUrl}`);
})
.catch(error => {
console.error(`Error creating mock: ${error.message}`);
});
After running these examples, you will receive a unique URL (link) for your mock endpoint and an adminUrl to manage it. You can then make requests to the generated link to retrieve the defined mock response.
Community libraries
The Mocky ecosystem benefits from community-driven development, with various developers creating libraries to streamline interaction with the Mocky API. These libraries often wrap the direct HTTP calls, providing more convenient and language-idiomatic ways to define and manage mock endpoints. While not officially supported or maintained by Mocky, these tools can offer enhanced developer experience.
When selecting a community library, consider its active maintenance, documentation, and the specific features it offers beyond direct API calls. Some libraries might provide:
- Simplified JSON payload construction for mock definitions.
- Convenience functions for common operations (e.g., creating a 200 OK mock).
- Integration with testing frameworks.
Examples of common approaches and potential community libraries include:
- Python: While the
requestslibrary is sufficient, a community wrapper might offer classes or functions specific to Mocky's payload structure, simplifying mock creation. Developers often build their own utility functions aroundrequestsfor repeated Mocky interactions. - JavaScript/Node.js: Given the prevalence of JavaScript in web development, several npm packages might exist that abstract Mocky API calls. Searching npm for
mockyormocky.iocan reveal community contributions. For example, a library might export functions likecreateMock(statusCode, body, headers). - Other Languages: Similar community efforts may exist for Java, Ruby, Go, and other languages. Developers typically search their language's package manager (e.g., Maven Central, RubyGems) or GitHub for relevant projects.
It is important to review the source code and community activity of any third-party library before integrating it into a production workflow. For general guidance on choosing and evaluating third-party libraries, resources like Google's advice on picking open-source libraries can be helpful. Always refer to the official Mocky API documentation for the most accurate and up-to-date information on endpoint structures and expected parameters, as community libraries may not always reflect the latest API changes immediately.