Thuta Learning
ProjectsWeb Developmentbeginner

REST API Intro

Relax. We'll talk through this in plain words — no textbook voice.

REST API is a set pattern for exchanging data between client and server. Browsers, mobile apps, and dashboard frontends send requests to the server, and the server sends back JSON data. In backend apps, the API acts as the main bridge between the two.

javascript
const express = require('express');
const app = express();

app.use(express.json());

let users = [
  { id: 1, name: 'Aung Aung' },
  { id: 2, name: 'Mya Mya' }
];

app.listen(3000, () => {
  console.log('User API running on http://localhost:3000');
});

This base code starts up an Express app and adds express.json() so it can read JSON request bodies. The users array is temporary in-memory data — it'll reset whenever the server restarts.

Info

In a real project you'd use a database. This lesson uses a plain in-memory array just to make the API structure easy to see clearly.

What's Next

In the next lessons, we'll add GET/POST routes on top of this base app.

Easy traps

  • If you want to read the POST body, you need to add app.use(express.json()) before your routes. Skip it and req.body may come back as undefined.
REST API Intro | Thuta Learning