REST API Without the Mess (No DB, No Stress)

Context : Welcome to the chill zone of backend development. In this blog, we’ll build a fully functional REST API — without touching a single database. That’s right, no MongoDB, no MySQL, not even a lonely JSON file. We’ll use in-memory dummy data to...

the_OldSchool_coder
REST API Without the Mess (No DB, No Stress)

Context :

Welcome to the chill zone of backend development. In this blog, we’ll build a fully functional REST API — without touching a single database. That’s right, no MongoDB, no MySQL, not even a lonely JSON file.

We’ll use in-memory dummy data to understand how APIs really work — focusing on routes, methods, status codes, and the overall flow. It’s the perfect starting point before diving into real-world backend madness.

So grab your Postman and let’s ship some fake data like pros.


Pre-requisite :

In the previous blog I have discussed about all the jargons of REST API. Please check out that . After that We will continue with this project .

here is the setup guide for the project . Using ( node express and nodemon )


Code

  • Making basic server :

Let’s Jump to code directly . Grab your coffee and let’s start

import express from "express"

const app = express();

app.get("/api", (req, res) => {
  res.send("helllo it's working!")
});

app.listen(3000, () => {
  console.log(`server is running on port 3000`)
})
  • This kick start the server


  • Making dummy data :

Let’s hard code the dummy data to reduce the complexity and understand

const products = [
  {
    name: "Laptop",
    price: 49999.99,
    quantity: 1,
    active: true
  },
  {
    name: "Wireless Mouse",
    price: 799.00,
    quantity: 2,
    active: true
  },
  {
    name: "Mechanical Keyboard",
    price: 2999.50,
    quantity: 1,
    active: false
  },
  {
    name: "27-inch Monitor",
    price: 13499.00,
    quantity: 1,
    active: true
  },
  {
    name: "USB-C Hub",
    price: 1499.00,
    quantity: 3,
    active: true
  },
  {
    name: "Noise Cancelling Headphones",
    price: 8999.99,
    quantity: 1,
    active: false
  },
  {
    name: "Webcam",
    price: 2199.00,
    quantity: 2,
    active: true
  },
  {
    name: "Gaming Chair",
    price: 12499.00,
    quantity: 1,
    active: true
  }
];
// dummy data

  • Reading all the product :

Reading the data from Product i.e. the dummy data . With get method

app.get("/api/products", (req, res) => {
  res.json(products);
})
// reading all product

So, we are passing the JSON data with named “ product “ directly … We are sending the response → JSON type .


  • Creating the product :

As We know for creating products we have post http method .

app.post("/api/products", (req, res) => {
  console.log(req.body)
  res.send("Okay")
})
// crateing product

here in the code , We are logging the req.body that have the JSON data we are sending through postman … Yes can't check the output in the browser. We have to send the req from postman and then from we will get the res ( with status code ).

  • So here we are using postman to send the JSON data and we are seeing that in postman that’s fine but in VS code it’s giving undefined .

  • The reason is we can't parse JSON data without any global middle-ware. So , We are using

    app.use(express.json()) . It will parse the data and now we can see it.


Update and Delete a product by ID →

app.put("/api/products/:id", (req, res) => {
  const product = products.find(product => product.id == req.params.id)
  if (!product) {
    res.status(404).json({
      "message": "WTH go away"
    })
  }

  const { name, price, quantity, active } = req.body;
  if (!name) {
    res.json({
      "msssage": "Nah hain bhai",
    })
  }
// used previously 
  if (name) {
    product.name = name
  }
  if (price) {
    product.price = price
  }
  if (quantity) {
    product.quantity = quantity
  }
  if ("active" in req.body) {
    product.active = active
  }
  res.status(201).json({
    "messgae": "Update is workingg"
  })
})

app.delete("/api/products/:id", (req, res) => {
  const productIndex = products.find(productIndex => productIndex.id == req.params.id)
  if (productIndex == -1) {
    res.status(404).json({
      "messgae": "hey unexpected backchodi!"
    })
  }

  products.splice(productIndex, 1)
  res.status(201).json({
    "message": "Delete is working!!!"
  })

})

In this code, We are using splice and find … function . And In every routes we are using dynamic parameter :id. Moreover, what the thing that is after base_url/xyz → here xyz is parameter.

here is the full raw code.

import express from "express"
import crypto from "crypto";

const app = express();

app.use(express.json())

const products = [  {
    id: "0bf735e2-fb4a-445a-9dcd-7b672ce62993",
    name: "Laptop",
    price: 49999.99,
    quantity: 1,
    active: true
  },
  {
    id: "0bf735e2-fb4a-445a-9dcd-7b672ce62994",
    name: "Wireless Mouse",
    price: 799.00,
    quantity: 2,
    active: true
  },
  {
    id: "0bf735e2-fb4a-445a-9dcd-7b672ce62997",
    name: "Mechanical Keyboard",
    price: 2999.50,
    quantity: 1,
    active: false
  },
  {
    id: "0bf735e2-fb4a-445a-9dcd-7b672ce62999",
    name: "27-inch Monitor",
    price: 13499.00,
    quantity: 1,
    active: true
  },
  {
    id: "0bf735e2-fb4a-445a-9dcd-7b672ce62990",
    name: "USB-C Hub",
    price: 1499.00,
    quantity: 3,
    active: true
  },
  {
    id: "0bf735e2-fb4a-445a-9dcd-7b672ce62995",
    name: "Noise Cancelling Headphones",
    price: 8999.99,
    quantity: 1,
    active: false
  },
  {
    id: "0bf735e2-fb4a-445a-9dcd-7b672ce629988",
    name: "Webcam",
    price: 2199.00,
    quantity: 2,
    active: true
  },
  {
    id: "0bf735e2-fb4a-445a-9dcd-7b672ce629977",
    name: "Gaming Chair",
    price: 12499.00,
    quantity: 1,
    active: true
  }
];
// dummy data

app.get("/api", (req, res) => {
  res.send("helllo it's working!1")
});

app.get("/api/products", (req, res) => {

  res.json(products);
})
// reading all product


app.post("/api/products", (req, res) => {

  const { name, price, quantity, active } = req.body;
  if (!name) {
    res.status(422).json(
      { "message": "nahi honga bhai" }
    )
  }
  const id = crypto.randomUUID()
  products.push({ id, name, price, quantity, active })
  res.status(201).json({ "masage": "product is added", id })

})
// crateing product



app.get("/api/products/:id", (req, res) => {
  const product = products.find(product => product.id == req.params.id)
  if (!product) {
    res.status(404).json({
      "message": "WTH go away"
    })
  }
  res.status(201).json(product)
})
// get a product by :id

app.put("/api/products/:id", (req, res) => {
  const product = products.find(product => product.id == req.params.id)
  if (!product) {
    res.status(404).json({
      "message": "WTH go away"
    })
  }

  const { name, price, quantity, active } = req.body;
  if (!name) {
    res.json({
      "msssage": "Nah hain bhai",
    })
  }
  if (name) {
    product.name = name
  }
  if (price) {
    product.price = price
  }
  if (quantity) {
    product.quantity = quantity
  }
  if ("active" in req.body) {
    product.active = active
  }
  res.status(201).json({
    "messgae": "Update is workingg"
  })
})
// update data 

app.delete("/api/products/:id", (req, res) => {
  const productIndex = products.find(productIndex => productIndex.id == req.params.id)
  if (productIndex == -1) {
    res.status(404).json({
      "messgae": "hey unexpected backchodi!"
    })
  }

  products.splice(productIndex, 1)
  res.status(201).json({
    "message": "Delete is working!!!"
  })

})
// delteing data

app.listen(3010, () => {
  console.log(`server is running on port 3010`)
})

Conclusion :

We’ve nailed all the CRUD operations using REST API — no database, no stress! Now, let’s clean up our code and organize it better with a proper folder structure.

Check out the GitHub repo for hands-on practice:
🔗 GitHub Repo

Next up: cleaner code, modular files, and pro-level structure. Let’s build better!