1.0.15 • Published 2 years ago

@vstoodeeoh/apiduck v1.0.15

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Virtual Stoodeeoh - API DUCK

API DUCK is a tool built for generating API documentation for Virtual Stoodeeoh clients.

Requirements

  • Express Server
  • VS Client ID

Install

npm i @vstoodeeoh/apiduck

Example Setup

Initialize API DUCK

// Import Packages
const apiDuck = require("apiduck");
const express = require("express");
const cors = require("cors");

//Routes
const ProjectRoute = require("./routes/projects");

const app = express();

// Setting Up API DUCK
apiDuck.init(
  "VStoodeeo", // Project Name
  "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled.", // Describe your project
  "1.0.0", // API Version
  "http://localhost:5555" // API URL (no / in the end of url)
);

// Setting Up Route Groups
apiDuck.setGroups([
  {
    name: "Projects",
    key: "projects",
  },
  {
    name: "Users",
    key: "users",
  },
]);

// Middlewares
app.use(cors({ credentials: true, origin: true }));
app.use(express.json({ limit: "50mb" }));

app.use("/projects", ProjectRoute);

apiDuck.listen(app, "clientID");

app.listen(process.env.PORT || 5555, () => {
  console.log("Server running on port " + 5555);
});

Setting Up Specific Routes

router.put("/projects/:id", async (req, res) => {
  // Your code
  return res.json({
      name: "test",
      date: 12-23-2323,
    });
});

apiDuck.setRoute({
  type: "PUT", // PUT, POST, GET, DELETE
  url: "/projects/{id}", // URL
  heading: "Update specific project", // Title for the route
  key: "update-specific-project", // Unique key for the route
  description: "Update specific project", // Description for the route
  groupKey: "projects", // Group key for the route
  notes: [
    // Notes you wanna leave for special cases
    {
      type: "info",
      text: "An ID of 123 will return a valid project",
    },
    {
      type: "warning",
      text: "Some warning",
    },
  ],
  headers: [
    // Headers for the route
    {
      key: "Content-Type",
      value: "application/json",
      description: "Content type of the request",
    },
  ],
  queries: [
    // URL ? queries
    {
      name: "id",
      type: "integer",
      description: "ID of the project",
      required: true,
    },
  ],
  parameters: [
    // Body Parameters
    {
      name: "id",
      default: "null",
      description: "Unique ID of the project",
      required: true,
    },
  ],
  responses: [
    // Response codes
    {
      status: 200,
      description: "User found",
    },
    {
      status: 404,
      description: "Not Found",
    },
  ],
  returns: {
    // Return object
    type: "object",
    object: {
      name: "test",
      date: 12-23-2323,
    },
  },
});

Required Fields

init

  • project name (Required)
  • project description (Required)
  • API version (Required)
  • API url (No / end of url) (Required)

setGroups

  • name (Required)
  • key (Required)

setRoute

  • type (Required)
  • url (Required)
  • heading (Required)
  • description (Required)
  • groupKey (Required)
  • notes (Not Required)
  • parameters (Not Required)
  • responses (Required)
  • returns (Required)

Notes

This is a serverside tool that would generate a JSON file for the documentation. It does not include an UI but can be utilized with an UI tool of user's need.

Virtual Stoodeeoh Inc.

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago