apideck-express
v1.0.1
Published
Lightweight, beautiful, zero-config API playground and explorer for Express.js APIs
Downloads
140
Maintainers
Readme
apideck-express
Lightweight, beautiful, zero-config API playground and explorer for Express.js APIs.
ApiDeck automatically inspects your Express routing stack to generate a beautiful UI allowing you to browse, test, and document your API without writing manual OpenAPI YAML files.
Features
- Zero Config: Just plug the middleware into your Express app and you're done.
- Dynamic Schema Reflection: Attach classes or schemas to your route handlers, and ApiDeck will automatically infer the structure and generate mock JSON examples.
- Modern UI: Sleek, fully responsive, dark-mode ready interface.
- Automatic Grouping: Endpoints are automatically grouped by root path (e.g.,
/api/users).
Installation
npm install apideck-expressQuick Start
Register the middleware by passing your Express app instance:
const express = require('express');
const apideck = require('apideck-express');
const app = express();
app.use(express.json());
// ... define your routes ...
app.get('/api/users', (req, res) => {
res.json([{ id: 1, name: 'John Doe' }]);
});
// Enable ApiDeck
app.use('/apideck', apideck({
app: app, // Pass your express instance!
title: 'My Express API',
version: '1.0.0',
description: 'Explore my Node.js Express API dynamically'
}));
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000');
console.log('Explore your API at http://localhost:3000/apideck');
});Now open http://localhost:3000/apideck in your browser!
Advanced: Dynamic Schema Reflection (Auto-Example Generation)
Unlike strongly typed languages, standard Node.js routing doesn't provide types for request/response bodies natively. However, ApiDeck includes a powerful introspection engine.
To have ApiDeck auto-generate Example JSON payloads and schema properties in the UI, you can simply attach a Class or Object to the .schema (or .model, .DTO) property of your route handler!
Using a Class (DTO)
If you define a class with default properties, ApiDeck will instantiate it and extract the types automatically:
// Define a DTO class with default values so ApiDeck can read the types
class CreateUserDTO {
constructor() {
this.name = "John Doe";
this.email = "[email protected]";
this.isActive = true;
this.age = 30;
}
}
// Your route handler
const createUser = (req, res) => {
res.status(201).json({ success: true });
};
// Attach the class to the handler!
createUser.schema = CreateUserDTO;
app.post('/api/users', createUser);Using a Raw Object
Alternatively, you can just pass a raw object describing the OpenAPI properties directly:
const updateUser = (req, res) => res.json({ success: true });
updateUser.schema = {
properties: {
role: { type: 'string' },
permissions: { type: 'array' }
},
example: {
role: "admin",
permissions: ["read", "write"]
}
};
app.patch('/api/users/:id', updateUser);When you open the ApiDeck UI, the POST/PUT/PATCH routes will now automatically display interactive JSON examples!
