@mockeroo/mock-responses
v1.4.0
Published
Responses that mock you.
Downloads
412
Maintainers
Readme
@mockeroo/mock-responses
Responses that mock you. An npm package that provides sarcastic, judgmental HTTP responses you can mount in your own Express app.
Try It Live
A live server running this package is available at https://mock-server.mockeroo.workers.dev/
Hit it directly from your terminal — no installation required:
# Project info and available status codes
curl https://mock-server.mockeroo.workers.dev/
# Get a sarcastic 404
curl https://mock-server.mockeroo.workers.dev/404
# Get a sarcastic 500
curl https://mock-server.mockeroo.workers.dev/500
# Or use it as a real mock endpoint in your tests
curl -i https://mock-server.mockeroo.workers.dev/418Each endpoint returns the actual HTTP status code, so it works as a real mock server for testing error handling.
Installation
npm install @mockeroo/mock-responsesUsage
getResponse(statusCode)
Returns a random sarcastic { status, message } object for the given HTTP status code, or null if unavailable.
const { getResponse } = require('@mockeroo/mock-responses');
const result = getResponse(404);
// { status: 404, message: "Whatever you're looking for, it's not here. Just like my will to help you." }
const missing = getResponse(999);
// nullgetAvailableCodes()
Returns a sorted array of all available HTTP status codes.
const { getAvailableCodes } = require('@mockeroo/mock-responses');
console.log(getAvailableCodes());
// [200, 201, 204, 301, 302, 304, 400, 401, 403, 404, ...]middleware()
Returns an Express router you can mount at any path:
const express = require('express');
const { middleware } = require('@mockeroo/mock-responses');
const app = express();
app.use('/mock', middleware());
app.listen(3000);This gives you:
GET /mock/— project info and available codesGET /mock/:statusCode— sarcastic response with the real HTTP status code
Example Response
{
"status": 404,
"message": "Whatever you're looking for, it's not here. Just like my will to help you."
}The response actually comes back with HTTP status 404 — so it works as a real mock endpoint for testing how your app handles different status codes. Except now the errors are personal.
Full Example
const express = require('express');
const cors = require('cors');
const rateLimit = require('express-rate-limit');
const { middleware } = require('@mockeroo/mock-responses');
const app = express();
app.use(cors());
const limiter = rateLimit({
windowMs: 60 * 1000,
max: 120,
message: { status: 429, message: "Rate limit exceeded." }
});
app.use(limiter);
app.use('/', middleware());
app.listen(3000, () => {
console.log('Server running on port 3000');
});Available Status Codes
200 201 204 301 302 304 400 401 403 404 405 408 409 413 418 429 500 502 503 504
Want more? Contribute one!
Contributing
The easiest way to contribute is by adding funny messages to files in the responses/ directory. See CONTRIBUTING.md for guidelines.
License
MIT
