← Back to Node.js Course | Chapter 8: Working with APIs | Lesson 1 of 7

REST API के Basics

REST URLs और standard HTTP methods वाले resources के आसपास APIs design करने की एक style है।

In this page:

  1. REST API Basics

REST API Basics

Resources nouns हैं जैसे /users और /users/42। Methods actions express करते हैं: GET पढ़ता है, POST बनाता है, PUT या PATCH update करता है, और DELETE remove करता है। Responses JSON और meaningful status codes इस्तेमाल करते हैं। Stateless requests APIs को scale करना आसान बनाते हैं।

Note: Collections के लिए plural nouns इस्तेमाल करें।

उदाहरण: REST API basics

javascript
const routes = [
  ["GET", "/users", "list users"],
  ["POST", "/users", "create a user"],
  ["GET", "/users/:id", "read one user"],
  ["PATCH", "/users/:id", "update a user"],
  ["DELETE", "/users/:id", "delete a user"],
];
for (const [m, p, d] of routes) console.log(m.padEnd(6), p.padEnd(11), d);

// Output:
// GET    /users      list users
// POST   /users      create a user
// GET    /users/:id  read one user
// PATCH  /users/:id  update a user
// DELETE /users/:id  delete a user

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. /getUsers जैसे URLs में verbs डालना
  2. status codes ignore करना
  3. server पर session state store करना
चैप्टर सारांश
  • Resources nouns हैं
  • HTTP methods verbs हैं
  • JSON responses इस्तेमाल होते हैं
  • Requests stateless होती हैं
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.