+91-9801012345
Apply Now
Haridwar University Logo
16 Years
Admissions Open 2027 – Top Placement University + Scholarship up to 50% Apply Now!
REST API Examples for Beginners: Build Your First API Project
Engineering
November 30, 2026
10 min read

REST API Examples for Beginners: Build Your First API Project

Dr. Himanshu Verma

Associate Professor & HOD, Computer Science & Engineering, Haridwar University

A frontend application may need to display student details, add a new record or update an existing one. It needs a reliable way to communicate with the backend and exchange information. This is where REST APIs become useful.

For students learning web development, REST API examples are easier to understand when they are connected to a working application rather than studied as isolated definitions. A GET request retrieves information; a POST request creates a record; PUT and PATCH update it; DELETE removes it.

I recommend starting with a small project and understanding each request before moving to more advanced API development. In this guide, we will build a Student Records API using Node.js and Express, then test its endpoints.

1. What REST APIs Mean in Web Development

REST stands for Representational State Transfer. It is an architectural style for designing networked applications. An API, or Application Programming Interface, defines how one software component communicates with another.

A RESTful API commonly uses HTTP to exchange resources between a client and a server. For example, a student portal can request a list of available courses from a backend API. The server processes the request and returns the data, often in JSON format.

REST is associated with six architectural constraints: client-server separation, statelessness, cacheability, a uniform interface, a layered system and optional code on demand. Beginners should first understand the practical implications of the first few:

  • Client-server: The frontend and backend have separate responsibilities.
  • Statelessness: Each request carries the information needed to process it; the server does not rely on stored client-session context to understand that request.
  • Cacheability: Responses can indicate whether they may be stored and reused.
  • Uniform interface: Resources are accessed through consistent identifiers and standard methods.

REST is not a programming language or a framework. Developers can build REST APIs using JavaScript, Python, Java and other technologies.

2. How a REST API Request and Response Work

A typical API interaction involves four elements:

  1. Client: A browser, mobile application or another software service.
  2. Endpoint: The URL identifying the resource or operation.
  3. HTTP method: Indicates what the client wants to do.
  4. Response: The server returns a status code and, where appropriate, data.

Suppose a student portal needs to retrieve student records. The client sends:

GET /api/students

The server might respond with:

{
  "students": [
    {
      "id": 1,
      "name": "Aarav Sharma",
      "email": "[email protected]"
    }
  ]
}

The response uses JSON, a lightweight data-interchange format. The client can read the returned fields and display them on the screen.

The key point is that the frontend does not need to know how the server stores the records. It needs to follow the API's agreed request and response format.

3. REST API Methods with Practical Examples

HTTP methods communicate the intended operation. The following examples use a student resource.

Method Purpose Example endpoint
GET Retrieve records /api/students
POST Create a record /api/students
PUT Replace an existing record /api/students/1
PATCH Partially update a record /api/students/1
DELETE Remove a record /api/students/1

Consider a POST request that creates a student:

{
  "name": "Aarav Sharma",
  "email": "[email protected]"
}

A successful response commonly uses 201 Created and returns the newly created resource.

PUT and PATCH are not interchangeable. PUT represents replacement of the target resource, while PATCH applies partial modifications. GET retrieves information without asking the server to change the resource.

These distinctions matter when designing predictable endpoints. The MDN reference to HTTP request methods explains their standard semantics.

4. Understanding REST API URLs and Endpoints

An endpoint identifies where a client can access a resource. Good API URLs usually describe resources rather than actions.

For a Student Records API, examples include:

  • /api/students – the student collection.
  • /api/students/1 – the student whose ID is 1.
  • /api/students?course=BCA – a filtered collection, if the API supports that query.

The number 1 is a path parameter. The course=BCA part is a query parameter.

A useful design habit is to keep resource names consistent and use HTTP methods to express the operation. For example, avoid creating separate action-style URLs such as /getStudents and /deleteStudent.

5. Building Your First REST API Project with Node.js

For this exercise, we will create a small Student Records API with GET, POST, PUT, PATCH and DELETE operations. It uses an in-memory array, so the data is suitable for learning but will reset when the server restarts.

Step 1: Prepare the project

Install Node.js, create a project folder and open its terminal:

mkdir student-api
cd student-api
npm init -y
npm install express

Create a file named app.js.

Step 2: Add the API code

const express = require("express");
const app = express();

app.use(express.json());

let students = [
  { id: 1, name: "Aarav Sharma", email: "[email protected]" },
  { id: 2, name: "Meera Singh", email: "[email protected]" }
];

let nextId = 3;

// Retrieve all students
app.get("/api/students", (req, res) => {
  res.json(students);
});

// Retrieve one student
app.get("/api/students/:id", (req, res) => {
  const student = students.find(
    s => s.id === Number(req.params.id)
  );

  if (!student) {
    return res.status(404).json({ message: "Student not found" });
  }

  res.json(student);
});

// Create a student
app.post("/api/students", (req, res) => {
  const { name, email } = req.body;

  if (!name || !email) {
    return res.status(400).json({
      message: "Name and email are required"
    });
  }

  const student = { id: nextId++, name, email };
  students.push(student);

  res.status(201).json(student);
});

// Replace a student's details
app.put("/api/students/:id", (req, res) => {
  const student = students.find(
    s => s.id === Number(req.params.id)
  );

  if (!student) {
    return res.status(404).json({ message: "Student not found" });
  }

  const { name, email } = req.body;

  if (!name || !email) {
    return res.status(400).json({
      message: "Name and email are required"
    });
  }

  student.name = name;
  student.email = email;

  res.json(student);
});

// Partially update a student
app.patch("/api/students/:id", (req, res) => {
  const student = students.find(
    s => s.id === Number(req.params.id)
  );

  if (!student) {
    return res.status(404).json({ message: "Student not found" });
  }

  if (req.body.name !== undefined) student.name = req.body.name;
  if (req.body.email !== undefined) student.email = req.body.email;

  res.json(student);
});

// Delete a student
app.delete("/api/students/:id", (req, res) => {
  const index = students.findIndex(
    s => s.id === Number(req.params.id)
  );

  if (index === -1) {
    return res.status(404).json({ message: "Student not found" });
  }

  students.splice(index, 1);
  res.status(204).send();
});

app.listen(3000, () => {
  console.log("Student API running on port 3000");
});

Step 3: Start the server

node app.js

The API is now available at http://localhost:3000. The express.json() middleware parses incoming JSON request bodies, while Express routes connect each HTTP method and URL to its handler. The official Express routing guide explains how route methods and handlers work.

6. Testing REST API Endpoints with Postman

Writing the code is only part of the exercise. Test each endpoint to confirm that the server returns the expected result. Open Postman, create a request and use http://localhost:3000 as the base address.

Test Method and URL Expected result
List students GET /api/students 200 OK
Find student 1 GET /api/students/1 200 OK
Add student POST /api/students 201 Created
Replace student 1 PUT /api/students/1 200 OK
Update email only PATCH /api/students/1 200 OK
Delete student 1 DELETE /api/students/1 204 No Content

For POST, select Body → raw → JSON and enter:

{
  "name": "Riya Verma",
  "email": "[email protected]"
}

After sending the request, use GET /api/students to check whether the new record appears. Then try updating and deleting it. This sequence is more useful than testing each method independently because it shows how one API manages the same resource throughout its lifecycle.

7. Common REST API Errors and Their Solutions

A working API should also handle unsuccessful requests clearly.

Status code Meaning Example
200 OK A record is retrieved or updated Fetching student list or updating a student
201 Created A new student is added Creating a record with POST
204 No Content A student is deleted successfully Removing a record with DELETE
400 Bad Request Required fields are missing Sending POST without name or email
404 Not Found The requested student ID does not exist Requesting /api/students/99
500 Internal Server Error An unexpected server-side failure occurs Unhandled exception in route handler

A 404 response does not necessarily mean the server is unavailable. It can mean that the requested resource does not exist. Similarly, a 400 response indicates that the request needs correction.

Students should test invalid IDs, missing fields and unexpected input, not just successful requests. The MDN guide to HTTP response status codes provides the wider reference.

8. Improving Your First API Project

The example uses an array because it keeps the first exercise focused on routes and HTTP methods. It is not a production storage solution: restarting the server resets the records.

Once the basic API works, consider these improvements:

  • Database integration: Store records in MySQL, PostgreSQL or MongoDB.
  • Input validation: Check email formats, required fields and acceptable values.
  • Authentication: Restrict access to operations that should not be public.
  • Documentation: Describe endpoints, parameters, request bodies and responses.
  • Automated testing: Test successful requests, invalid input and missing records.

Students exploring broader software projects can also review HU's final-year project ideas for CSE and AI/ML students. Understanding how APIs connect application components also supports the fundamentals covered in our guide to system design for beginners. For programming preparation alongside project work, see the semester-wise DSA roadmap for placement preparation.

9. FAQs

1. What is a REST API in simple terms?

A REST API is an interface that allows software components to communicate through resources and standard web methods. It commonly uses HTTP and exchanges data in formats such as JSON.

2. What are the four main REST API methods?

GET retrieves data, POST creates a resource, PUT replaces a resource and DELETE removes it. PATCH is also commonly used for partial updates.

3. Which programming language is best for building a REST API?

There is no single best language. JavaScript with Node.js, Python and Java are all common choices. Beginners can start with the language they already understand.

4. What is the difference between REST and RESTful API?

REST is an architectural style. A RESTful API is an API designed in accordance with REST principles.

5. Can I test a REST API without building a frontend?

Yes. Tools such as Postman allow you to send HTTP requests, provide JSON bodies and inspect server responses without creating a user interface.

6. What is the difference between PUT and PATCH?

PUT is used to replace the target resource, while PATCH applies partial changes. The distinction helps clients communicate their intended update clearly.

7. Is an in-memory array suitable for a real REST API project?

It is useful for learning and small demonstrations, but it does not provide persistent storage. A project that needs records to survive server restarts should use a database.

10. Building Stronger API Development Skills

My advice is to avoid treating REST API development as a list of methods to memorise. Build a small application, send requests, inspect responses and test what happens when something goes wrong. Then replace temporary storage with a database and introduce validation and authentication.

A student who can explain the purpose of each endpoint, demonstrate a working request and justify the design decisions has learned more than someone who has only copied an API tutorial. That practical understanding is a useful foundation for larger software projects and further study in backend development.

Master Backend & Full-Stack Development at Haridwar University

Build real-world APIs, scalable web applications, and industry-ready engineering skills through hands-on computing programmes.

Chat with
HU
Admission
Team