๐ How to Use My Node.js API with Swagger: A Beginner's Guide with Metaphors, Examples & Project Ideas

Have you ever built a simple machine โ maybe a LEGO car, a paper plane, or even a sandcastle with tunnels? Thatโs exactly what an API is: a system with defined parts that serve a purpose and can be used by others. In this post, Iโll walk you through how to understand and use my Node.js REST API, how Swagger makes it easy, and how you can build your own mini-projects with it. Whether you're a DevOps learner, a full-stack newbie, or just API-curious, this post is for you.
๐งฑ What is This API?
This API is a simple inventory management system โ think of it like a digital cupboard. You can:
Add items to the cupboard (
POST /api/items
)See what's inside (
GET /api/items
)Update an item (
PUT /api/items/:id
)Remove an item (
DELETE /api/items/:id
)Check if the API is alive (
GET /api/health
)
It runs on Node.js + Express on Rocky Linux, and now comes with full Swagger documentation for ease of use.
๐ What is Swagger? (The Tour Guide ๐งญ)
Swagger is like a tour guide that walks you through every door and switch in your API. Instead of reading a boring manual, Swagger gives you an interactive dashboard where you can:
See all API endpoints
Understand what they do
Try them out directly from the browser
Live Example:
If your API is running on http://localhost:3000
, you can access Swagger UI at:
http://localhost:3000/api-docs
It looks like this:
๐ ๏ธ Setting Up: Quick Start
If you're a beginner, here's how you can get started using my API:
1. Clone and Install
git clone https://github.com/yourname/api_mgmt.git
cd api_mgmt
npm install
2. Run It Locally
npm start
Now open http://localhost:3000/api-docs to view Swagger UI.
๐งช How to Use Each Endpoint (With Real-World Metaphors)
๐ /api/health
โ Is the Machine On?
This endpoint checks the "pulse" of the server. It's like asking: โHey, are you awake?โ
curl http://localhost:3000/api/health
Response:
{ "status": "ok", "message": "API is running" }
๐ฆ /api/items
โ The Inventory Shelf
โ POST /api/items
โ Add an Item (๐)
Imagine putting a book on a shelf. Use this to add a new item.
Request:
{
"id": 1,
"name": "Notebook",
"quantity": 5
}
๐ GET /api/items
โ View All Items (๐)
This is like opening the cupboard to see whatโs inside.
โ๏ธ PUT /api/items/:id
โ Update an Item (๐ช)
Change an itemโs quantity or name.
๐๏ธ DELETE /api/items/:id
โ Remove an Item (๐ฎ)
Take an item off the shelf.
All of this is interactive via Swagger โ click, fill, and test!
๐ก Project Ideas Using This API
Here are some beginner-friendly project ideas:
1. ๐ Inventory Tracker Web App
Use this API as a backend and build a frontend in React/Vue. Visualize item counts in a dashboard.
2. ๐ Shopping Cart CLI
Write a terminal-based app in Python or Node.js that interacts with this API. Practice CRUD operations via CLI.
3. ๐ฑ Mobile Checklist App
Use Flutter or React Native to consume this API as a โto-doโ or inventory checklist.
4. ๐ฆ IoT Inventory Counter
Simulate devices adding items to the API (like sensors in a warehouse). Use it to understand POST requests and automation.
๐ Bonus: How Swagger is Set Up
You can set up Swagger using two packages:
npm install swagger-ui-express swagger-jsdoc
Then in server.js
:
const swaggerUi = require('swagger-ui-express');
const swaggerJsDoc = require('swagger-jsdoc');
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'Simple Node.js API',
version: '1.0.0',
},
},
apis: ['./routes/*.js'], // JSDoc comments live here
};
const swaggerSpec = swaggerJsDoc(options);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
Then use JSDoc-style comments in routes/items.js
:
/**
* @swagger
* /api/items:
* get:
* summary: Get all items
* responses:
* 200:
* description: List of items
*/
๐ Whatโs Next?
Youโve just learned how to use a simple API with real documentation, tested it, and maybe even dreamed up a few apps. Want to keep going?
Next steps:
๐ Add authentication (e.g., JWT tokens)
๐ณ Containerize the API with Docker
๐งช Write test cases with Jest or Supertest
โ๏ธ Deploy it to the cloud (AWS/DigitalOcean)
๐ฃ๏ธ Final Thoughts
APIs donโt have to be intimidating. With Swagger, they become approachable โ like walking into a smart home where everything is labeled and responsive. This is your first step toward full-stack confidence or DevOps wizardry.
๐ ๏ธ Try the API. Break it. Rebuild it. Extend it. Thatโs how you grow.
๐จโ๐ป Repo Link
๐ GitHub - api_mgmt
Subscribe to my newsletter
Read articles from Santosh Nc directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Santosh Nc
Santosh Nc
I believe, "Hard work beats Talent when Talent doesn't work hard". A Technophile specialising in DevOps.Currently Employed at DevOps Engineer. Shaping my career with Jenkins,Docker, Automation,Poweshell, Python and other devops tools.