@sazzad-anwar/api-docs
v0.1.13
Published
A nodejs module that will give you a postman like ui for api calls with the express app
Downloads
26
Maintainers
Readme
api-docs
Api-docs is a module that will give you an interface for making api documentation and make request. In express we need to write a lot of parameters in commented format for an API.
Install
npm install @sazzad-anwar/api-docs
Or installing with yarn? yarn add @sazzad-anwar/api-docs
Or installing with pnpm? pnpm add @sazzad-anwar/api-docs
Usage
Create a .json
file in the root of your project:
apiDocs.json
[]
Now follow the code snippet to get the api-docs working on your express app.
const express = require('express');
const { serveApiDocs } = require('@sazzad-anwar/api-docs');
const cors = require('cors');
const app = express();
const path = require('path');
const dir = path.join(__dirname, 'DIR_OF_YOUR_JSON_THAT_YOU_HAVE_CREATED_BEFORE');
const port = process.env.PORT || 5000;
app.use(cors());
app.get('/', (req, res) => {
res.json({ message: 'App is working' });
});
serveApiDocs(app, dir, 'production');
app.listen(port, () => console.log(`Server is running on port ${port}`));
Or using Typescript?
import express, { Express, Request, Response } from 'express';
import { serveApiDocs } from '@sazzad-anwar/api-docs';
import cors from 'cors';
import path from 'path';
const dir: string = path.join(__dirname, 'DIR_OF_YOUR_JSON_THAT_YOU_HAVE_CREATED_BEFORE');
const port: string = process.env.PORT || 5000;
const app: Express = express();
app.use(cors());
app.get('/', (req, res) => {
res.json({ message: 'App is working' });
});
serveApiDocs(app, dir, 'production');
app.listen(port, () => console.log(`Server is running on port ${port}`));
Here development
parameter will give the edit access to the api collections, api details and delete the api collection. But production
parameter will not give that access.
Yeah! that's it. Now when you run your express app the api docs will also be running on /docs
route.
[your app running route:port]/docs