Hackforge Academy

Category: javascript

what is rest api in frontend

Published on 18 Jun 2026

Explanation

A REST API in frontend is used to communicate with a backend server. The frontend sends HTTP requests (GET, POST, PUT, DELETE) and receives data, usually in JSON format. This allows web pages to fetch, display, create, update, or delete data without reloading the page.

Code:

fetch('https://jsonplaceholder.typicode.com/users')
  .then(response => response.json())
  .then(data => {
    console.log(data);
  })
  .catch(error => {
    console.error(error);
  });

Explanation

GET request is used to retrieve data from the server.

Code:

fetch('/api/students')
  .then(res => res.json())
  .then(data => console.log(data));

Explanation

POST request is used to send new data to the server.

Code:

fetch('/api/students', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'Praveen',
    course: 'Java'
  })
});

Explanation

PUT request is used to update existing data on the server.

Code:

fetch('/api/students/1', {
  method: 'PUT',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'Praveen Kumar',
    course: 'Spring Boot'
  })
});

Explanation

DELETE request is used to remove data from the server.

Code:

fetch('/api/students/1', {
  method: 'DELETE'
});

๐Ÿš€ Learn Spring Boot with real-world projects

๐Ÿ’ก Build REST APIs step by step

๐Ÿง  Improve backend development skills

๐ŸŽฏ Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

๐Ÿ

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
โš›๏ธ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
โ˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community