Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
Node.js

GET and POST API in Express.js

Create JSON GET and POST endpoints with express.json body parsing.

GET and POST API in Express.js — a practical guide to Express GET POST API with clear examples you can reuse in real projects.

GET and POST API in Express.js — 38/55 in the Node.js series. Full playlist companion: Node.js complete course on YouTube. Prefer one article? Read the complete Node.js tutorial.

Short description

GET retrieves data. POST creates data. Enable `express.json()` so JSON bodies are available on `req.body`.

GET + POST notes API

const express = require('express');
const app = express();
app.use(express.json());

const notes = [];

app.get('/api/notes', (req, res) => res.json(notes));

app.post('/api/notes', (req, res) => {
  const note = { id: Date.now(), text: req.body.text };
  notes.push(note);
  res.status(201).json(note);
});

app.listen(3000);

Leave a reply

Your email address will not be published. Required fields are marked *