Updated November 2026: The old mock platform is gone. This guide now covers mock servers last published before November 9, 2024, which must be republished to work again. For everything else, see How code-based mocks work.
On November 9, 2024, APIGIT launched a new MockServer backend, powered by Express.js and running in a Node.js sandbox environment. The old platform, at *.mock.apigit.com, has since been retired.
If your mock server was last published before that date, it is not reachable until you republish it. If you were sent here by a notice on your mock server's page, this guide is for you. Moving from the old version (pure JavaScript-based) to the new one involves some breaking changes.
apigit-mock/ folder, as described below. apigit-mock/main.js must exist.Publish Center and click Republish, which rebuilds it from the same commit and name. If you changed your scripts, overwrite the mock server from your new commit instead.On the Free plan? You can't republish a code-based mock server, but you can publish a new spec-based mock server from your OpenAPI document: it needs no scripts and works on every plan. To keep the responses your scripts returned, add them to the document as example values. See Migrating from a code-based mock.
Old URL format: your-mockserver.mock.apigit.com
New URL format: your-mockserver.mockserver.apigit.com
The old URL no longer answers. A republished mock server keeps its name, under the new host.
Example:
https://your-mockserver.mock.apigit.com/endpointhttps://your-mockserver.mockserver.apigit.com/endpointBe sure to update any references in your client applications, documentation, and integrations.
In the old MockServer, several popular JavaScript libraries were globally available, allowing direct usage without explicit imports. These included:
_) (v4.17.21) - General utility functionsmoment) (v2.30.1) - Time and date handlingfaker) (v5.5.3) - Data generatorAjv) (v6.10.0) - JSON schema validationvalidator) (v13.12.0) - Validation helperIn the new version of MockServer, these libraries must now be manually imported using require statements in your mock scripts before use. An import statement does not find them.
require statements for any supported libraries used in your mock scripts.The new MockServer comes with popular JavaScript libraries pre-installed. It has no network access, so a library must be on this list or included in your apigit-mock/ folder. Below is a list of supported libraries and examples of how to use them:
Example Usage:
var moment = require('moment'); // require
const { faker } = require('@faker-js/faker');
const Ajv = require("ajv");
var validator = require('validator');
const base64 = require('base64-js');
const jwt = require('jsonwebtoken');
const { v4: uuidv4 } = require('uuid');
const _ = require('lodash');
function testLodash() {
// Test data
const users = [
{ id: 1, name: 'Alice', age: 25, active: true },
{ id: 2, name: 'Bob', age: 30, active: false },
{ id: 3, name: 'Charlie', age: 35, active: true },
{ id: 4, name: 'David', age: 40, active: false }
];
// Example 1: Filter active users
const activeUsers = _.filter(users, { active: true });
console.log('Active Users:', activeUsers);
// Example 2: Sort users by age in descending order
const sortedByAge = _.orderBy(users, ['age'], ['desc']);
console.log('Users sorted by age (desc):', sortedByAge);
// Example 3: Get the names of all users
const userNames = _.map(users, 'name');
console.log('User Names:', userNames);
}
function testMoment() {
console.log("Current time is:", moment().format());
}
function testUuidv4() {
console.log("UUID is:", uuidv4());
}
function testAjv() {
const ajv = new Ajv();
const schema = {
type: "object",
properties: {
foo: { type: "integer" },
bar: { type: "string" },
},
required: ["foo"],
additionalProperties: false,
};
const data = { foo: 1, bar: "abc" };
const validate = ajv.compile(schema);
const valid = validate(data);
if (!valid) console.log(validate.errors);
}
function testBase64() {
const text = 'Hello, world!';
const textBytes = new TextEncoder().encode(text);
const base64Encoded = base64.fromByteArray(textBytes);
console.log('Base64 Encoded:', base64Encoded);
const decodedBytes = base64.toByteArray(base64Encoded);
const decodedText = new TextDecoder().decode(decodedBytes);
console.log('Decoded Text:', decodedText);
}
function testValidator() {
const result = validator.isEmail('fooo~bar.com');
console.log("fooo~bar.com is email, right?", result);
}
function testFakerJS() {
return {
userId: faker.string.uuid(),
username: faker.internet.username(),
email: faker.internet.email(),
avatar: faker.image.avatar(),
password: faker.internet.password(),
birthdate: faker.date.birthdate(),
registeredAt: faker.date.past(),
};
}
function testJwt() {
const SECRET_KEY = 'your-secret-key';
const payload = { userId: 123, username: 'testUser' };
const token = jwt.sign(payload, SECRET_KEY, { expiresIn: '1h' });
console.log('Generated Token:', token);
try {
const decoded = jwt.verify(token, SECRET_KEY);
console.log('Decoded Payload:', decoded);
} catch (err) {
console.error('Token verification failed:', err.message);
}
}
mock.get("/testlibs", function (req, res) {
console.log("==== this is a test of libs supported =====");
testLodash();
testMoment();
testUuidv4();
testAjv();
testValidator();
testBase64();
testJwt();
const jsonData = testFakerJS();
return res.status(200).json(jsonData);
});
mock.define() and mock.[get|post|delete|...]()mock is now an express.js app, so you can define routes the native way with mock.[get|post|delete|...]().
mock.define(path, method, callback) still works, accepts {name} path parameters as well as :name, and is the way to have a route listed by GET /apigit-mockserver-routes.
Nothing is required for existing mock.define() routes. See Routes and Middleware.
Publish a mock server from your OpenAPI documents without writing code. It validates requests, answers from your examples and schemas, and works on every plan.
APIGit has two types of mock server. Here is how they differ, when each one fits, and how to run both from one repository.
Spec-based mock servers validate each request against your OpenAPI document, return clear problem+json errors, and let clients pick a response with the Prefer header.
Create a free workspace, add an OpenAPI file and publish your first API document and mock server in minutes.