REST API के Basics
REST URLs और standard HTTP methods वाले resources के आसपास APIs design करने की एक style है।
In this page:
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
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. #}
आम गलतियां
- /getUsers जैसे URLs में verbs डालना
- status codes ignore करना
- 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: