0.1.0 • Published 9 months ago
docsifier v0.1.0
Docsifier
A simple API documentation generator for your express app!
❓ Usage
Use this as any other package!
It's simple as that, just put the Docsifier.Middleware
in your listeners and it should work!
Example:
const Docsifier = require("docsifier");
const Express = require("express");
const app = Express();
// OPTIONAL: Custom settings
Docsifier.setup({
returningOnly: true
// [...]
})
// Here we include the middleware that will set everything for us!
app.use(Docsifier.Middleware);
app.get('/api/helloWorld', (req, res, next) => {
if(req.isDocsReq) return new Docsifier.DocsEntry({
description: "Example documentation entry!",
params: []
// [...]
})
res.json({ok: true});
});
const PORT = 80
app.listen(PORT, () => {
console.log(`Listening to ${PORT}`);
Docsifier.build(app); // Optional if you want to build page after running. By default it builds on first request to docs page.
});
⚙ Configuration
As I shown in a example above I used method Docsifier.setup
. It's a method which sets up this package!
👇 Options:
Name | Default | Description |
---|---|---|
docsPath | /docs | What path redirects user to documentation page. |
filePath | docs.html | What file should be a documentation template. If provided path doesn't exist it defualts to package's default template page. |
👇 Accessing endpoints data on template page:
When creating template page - you can access Docsifier data with _DOCSIFIER_DATA
variable in script!
👇 Setting endpoints data:
You can do it easily by using Docsifier.DocsEntry
class! Anything you'll put here will be passed to documentation page.
Example:
// [...]
app.get('/api/:ver/helloWorld', (req, res, next) => {
if(req.isDocsReq) return new Docsifier.DocsEntry({
description: "Prints Hello World in json object!"
})
res.json({msg: "Hello world!"})
})
// [...]
⚠ KEEP IN MIND: When package requests the DocsEntry
class from handler - the only thing it will pass to it is isDocsReq
property in first argument.
0.1.0
9 months ago