REST API Design Best Practices: Methods, Status Codes & Versioning Notes in Hindi & English : REST API डिज़ाइन सिद्धांत: HTTP मेथड्स, स्टेटस कोड और वर्जनिंग और 20 महत्वपूर्ण MCQ प्रश्न (India IT Exam)

Post a Comment

UGC-NET, GATE, NIELIT (O/A/B Level), KVS/NVS Computer Teacher, PGDCA, BCA, MCA, B-Tech व All India IT Exam विशेष नोट्स: इस अध्याय में हम REST API Design Best Practices: Methods, Status Codes & Versioning (REST API डिज़ाइन सिद्धांत: HTTP मेथड्स, स्टेटस कोड और वर्जनिंग) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और राष्ट्रीय स्तर की परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: REST (Representational State Transfer) is an architectural style for designing stateless, scalable web APIs over HTTP. Proper RESTful design relies on resource-oriented URIs, standard HTTP methods (GET, POST, PUT, PATCH, DELETE), accurate status codes, and clean API versioning.

अध्याय सार: REST (रिप्रेजेंटेशनल स्टेट ट्रांसफर) HTTP पर स्टेटलेस, स्केलेबल वेब API डिज़ाइन करने की एक आर्किटेक्चरल शैली है। उचित RESTful डिज़ाइन संसाधन-उन्मुख URIs, मानक HTTP मेथड्स (GET, POST, PUT, PATCH, DELETE), सटीक स्टेटस कोड और स्पष्ट API वर्जनिंग पर निर्भर करता है।

REST API Design Best Practices: Methods, Status Codes & Versioning: Detailed Notes & Architecture (REST API डिज़ाइन सिद्धांत: HTTP मेथड्स, स्टेटस कोड और वर्जनिंग)

1. REST Architectural Constraints (REST आर्किटेक्चरल बाधाएं)

[EN] Defined by Roy Fielding in 2000, REST enforces six constraints: Client-Server separation, Statelessness (each request contains all context needed, no server-side session), Cacheability, Uniform Interface, Layered System, and optional Code-on-Demand. Statelessness is critical because any backend server can handle any request, enabling horizontal scaling.

[HI] 2000 में रॉय फील्डिंग द्वारा परिभाषित, REST छह बाधाओं को लागू करता है: क्लाइंट-सर्वर पृथक्करण, स्टेटलेसनेस (प्रत्येक अनुरोध में सभी आवश्यक संदर्भ होते हैं), कैशेबिलिटी, यूनिफॉर्म इंटरफ़ेस, लेयर्ड सिस्टम और वैकल्पिक कोड-ऑन-डिमांड। स्टेटलेसनेस क्षैतिज स्केलिंग को सक्षम बनाती है।

2. HTTP Methods and Idempotency (HTTP मेथड्स और आइडेंटपोटेंसी)

[EN] REST maps CRUD operations to HTTP verbs: GET (Read), POST (Create), PUT (Full Replace), PATCH (Partial Update), and DELETE (Remove). GET, PUT, and DELETE are idempotent—repeating the exact same request multiple times produces the same server state as executing it once. POST is neither safe nor idempotent, as repeating it creates duplicate resources.

[HI] REST CRUD संचालन को HTTP वर्ब्स से मैप करता है: GET (पढ़ें), POST (बनाएं), PUT (पूर्ण प्रतिस्थापन), PATCH (आंशिक अपडेट), और DELETE (हटाएं)। GET, PUT और DELETE आइडेंटपोटेंट हैं—एक ही अनुरोध को बार-बार दोहराने से सर्वर की स्थिति वही रहती है। POST आइडेंटपोटेंट नहीं है।

3. HTTP Status Codes in REST APIs (REST APIs में HTTP स्टेटस कोड)

[EN] Status codes communicate outcomes clearly: 2xx indicates success (200 OK, 201 Created, 204 No Content), 4xx indicates client errors (400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests), and 5xx indicates server errors (500 Internal Server Error, 503 Service Unavailable). Using 201 Created with a Location header is best practice for POST.

[HI] स्टेटस कोड परिणाम स्पष्ट करते हैं: 2xx सफलता (200 OK, 201 Created, 204 No Content), 4xx क्लाइंट त्रुटि (400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests), और 5xx सर्वर त्रुटि (500 Internal Server Error, 503 Service Unavailable) दर्शाता है।

4. API Versioning and URI Best Practices (API वर्जनिंग और URI सर्वोत्तम अभ्यास)

[EN] REST URIs should use plural nouns representing resources (e.g., /api/v1/users/42) rather than verbs (e.g., /getUser). To avoid breaking existing clients when schemas evolve, APIs use versioning via URI path (/v1/users), query parameter (?version=1), or custom HTTP headers (Accept: application/vnd.api.v1+json).

[HI] REST URIs में क्रियाओं (/getUser) के बजाय संसाधनों का प्रतिनिधित्व करने वाली बहुवचन संज्ञाओं (जैसे /api/v1/users/42) का उपयोग करना चाहिए। स्कीमा बदलने पर मौजूदा क्लाइंट्स को टूटने से बचाने के लिए URI पाथ (/v1/users), क्वेरी पैरामीटर या कस्टम HTTP हेडर द्वारा वर्जनिंग की जाती है।

Syntax, Formula & Technical Example (REST API Design Best Practices: Methods, Status Codes & Versioning)

# RESTful API Endpoints Example
GET    /api/v1/students      -> 200 OK (List all students)
POST   /api/v1/students      -> 201 Created (Create new student)
GET    /api/v1/students/101  -> 200 OK (Fetch student 101)
PUT    /api/v1/students/101  -> 200 OK (Replace student 101)
PATCH  /api/v1/students/101  -> 200 OK (Update specific fields)
DELETE /api/v1/students/101  -> 204 No Content (Delete student 101)

REST API Design Best Practices: Methods, Status Codes & Versioning Quick Reference & Comparison Table

HTTP MethodIdempotent?Key Exam Fact
GETYes (Safe & Idempotent)Retrieves resource; no side effects
POSTNo (Not Idempotent)Creates new resource; returns 201 Created
PUTYes (Idempotent)Replaces entire resource at target URI
DELETEYes (Idempotent, removes resource)Removes resource; often returns 204 No Content

REST API Design Best Practices: Methods, Status Codes & Versioning Top 20 Bilingual MCQs with Answers

Q1. Who introduced the REST architectural style in his 2000 doctoral dissertation?

(2000 में अपने डॉक्टरेट शोध प्रबंध में REST आर्किटेक्चरल शैली किसने पेश की थी?)

(A) Vint Cerf

(B) Tim Berners-Lee

(C) Roy Fielding

(D) Linus Torvalds

Correct Answer: (C)

[EN] Roy Fielding defined REST while co-authoring the HTTP/1.1 specification.

[HI] रॉय फील्डिंग ने HTTP/1.1 स्पेसिफिकेशन के सह-लेखन के दौरान REST को परिभाषित किया।

Q2. Which HTTP method is NOT idempotent?

(कौन सा HTTP मेथड आइडेंटपोटेंट नहीं है?)

(A) GET

(B) PUT

(C) DELETE

(D) POST

Correct Answer: (D)

[EN] Repeating a POST request can create multiple duplicate resources.

[HI] POST अनुरोध को दोहराने से कई डुप्लिकेट संसाधन बन सकते हैं।

Q3. Which HTTP status code should be returned when a new resource is successfully created via POST?

(POST के माध्यम से नया संसाधन सफलतापूर्वक बनने पर कौन सा HTTP स्टेटस कोड लौटाया जाना चाहिए?)

(A) 201 Created

(B) 200 OK

(C) 204 No Content

(D) 301 Moved Permanently

Correct Answer: (A)

[EN] 201 Created indicates successful resource creation.

[HI] 201 Created सफल संसाधन निर्माण को इंगित करता है।

Q4. What is the difference between 401 Unauthorized and 403 Forbidden?

(401 Unauthorized और 403 Forbidden में क्या अंतर है?)

(A) They are identical

(B) 401 means unauthenticated; 403 means authenticated but lacks permission

(C) 401 means not found; 403 means timeout

(D) 401 is a server error; 403 is a client error

Correct Answer: (B)

[EN] 401 requires valid credentials; 403 means the server understands who you are but denies access.

[HI] 401 के लिए वैध क्रेडेंशियल आवश्यक हैं; 403 का अर्थ है कि आपके पास अनुमति नहीं है।

Q5. Which HTTP method is used for a partial update of an existing resource?

(मौजूदा संसाधन के आंशिक अपडेट के लिए किस HTTP मेथड का उपयोग किया जाता है?)

(A) PUT

(B) POST

(C) HEAD

(D) PATCH

Correct Answer: (D)

[EN] PATCH applies partial modifications, whereas PUT replaces the entire resource.

[HI] PATCH आंशिक संशोधन लागू करता है, जबकि PUT पूरे संसाधन को बदल देता है।

Q6. What does 'Statelessness' mean in REST?

(REST में 'स्टेटलेसनेस' का क्या अर्थ है?)

(A) The server does not store client session state between requests

(B) No authentication is allowed

(C) APIs cannot use JSON

(D) The database is read-only

Correct Answer: (A)

[EN] Every HTTP request must carry all information (e.g., JWT token) needed to process it.

[HI] प्रत्येक HTTP अनुरोध में इसे संसाधित करने के लिए आवश्यक सभी जानकारी (जैसे JWT टोकन) होनी चाहिए।

Q7. Which URI follows RESTful naming best practices?

(कौन सा URI RESTful नामकरण सर्वोत्तम अभ्यासों का पालन करता है?)

(A) POST /api/v1/createNewOrder

(B) GET /api/v1/orders/55

(C) DELETE /api/v1/deleteOrder/55

(D) GET /api/v1/getOrderById?id=55

Correct Answer: (B)

[EN] REST URIs use plural nouns for resources and rely on HTTP methods for actions.

[HI] REST URIs संसाधनों के लिए बहुवचन संज्ञाओं और क्रियाओं के लिए HTTP मेथड्स का उपयोग करते हैं।

Q8. Which status code is typically returned for a successful DELETE request with no response body?

(बिना रिस्पॉन्स बॉडी वाले सफल DELETE अनुरोध के लिए आमतौर पर कौन सा स्टेटस कोड लौटाया जाता है?)

(A) 201 Created

(B) 204 No Content

(C) 500 Internal Server Error

(D) 404 Not Found

Correct Answer: (B)

[EN] 204 No Content confirms success without needing to send a body.

[HI] 204 No Content बॉडी भेजे बिना सफलता की पुष्टि करता है।

Q9. Which HTTP status code indicates that a client has exceeded the API rate limit?

(कौन सा HTTP स्टेटस कोड इंगित करता है कि क्लाइंट ने API रेट लिमिट पार कर ली है?)

(A) 409 Conflict

(B) 429 Too Many Requests

(C) 502 Bad Gateway

(D) 400 Bad Request

Correct Answer: (B)

[EN] 429 Too Many Requests is used for rate limiting and throttling.

[HI] 429 Too Many Requests का उपयोग रेट लिमिटिंग के लिए किया जाता है।

Q10. Which data format is most commonly used in modern REST APIs?

(आधुनिक REST APIs में कौन सा डेटा प्रारूप सबसे अधिक उपयोग किया जाता है?)

(A) SOAP XML

(B) CSV

(C) JSON

(D) ASN.1

Correct Answer: (C)

[EN] JSON (JavaScript Object Notation) is lightweight and native to web browsers.

[HI] JSON हल्का है और वेब ब्राउज़र के लिए नेटिव है।

Q11. What does HATEOAS stand for in REST?

(REST में HATEOAS का क्या अर्थ है?)

(A) Hypermedia As The Engine Of Application State

(B) High Availability Traffic Engineering

(C) Hypertext Access To External Object Storage

(D) HTTP API Transport Encryption Over SSL

Correct Answer: (A)

[EN] HATEOAS means responses include hypermedia links guiding the client on valid next actions.

[HI] HATEOAS का अर्थ है कि प्रतिक्रियाओं में क्लाइंट को अगले वैध कार्यों पर मार्गदर्शन करने वाले हाइपरमीडिया लिंक शामिल होते हैं।

Q12. Which HTTP method retrieves only the response headers without the body?

(कौन सा HTTP मेथड बिना बॉडी के केवल रिस्पॉन्स हेडर प्राप्त करता है?)

(A) OPTIONS

(B) TRACE

(C) HEAD

(D) GET

Correct Answer: (C)

[EN] HEAD is identical to GET but omits the response body, useful for checking metadata.

[HI] HEAD, GET के समान है लेकिन रिस्पॉन्स बॉडी को छोड़ देता है।

Q13. Which status code represents a 5xx Server Error?

(कौन सा स्टेटस कोड 5xx सर्वर त्रुटि का प्रतिनिधित्व करता है?)

(A) 304 Not Modified

(B) 202 Accepted

(C) 503 Service Unavailable

(D) 404 Not Found

Correct Answer: (C)

[EN] 503 indicates the server is temporarily overloaded or down for maintenance.

[HI] 503 इंगित करता है कि सर्वर अस्थायी रूप से ओवरलोड या रखरखाव के लिए बंद है।

Q14. Which HTTP header tells the server what media type the client expects in response?

(कौन सा HTTP हेडर सर्वर को बताता है कि क्लाइंट प्रतिक्रिया में किस मीडिया प्रकार की अपेक्षा करता है?)

(A) Authorization

(B) Accept

(C) Content-Type

(D) User-Agent

Correct Answer: (B)

[EN] Accept (e.g., application/json) handles content negotiation.

[HI] Accept (जैसे application/json) कंटेंट नेगोशिएशन को संभालता है।

Q15. What is a common way to version a REST API?

(REST API को वर्जन करने का एक सामान्य तरीका क्या है?)

(A) URI path versioning like /api/v2/users

(B) Renaming the domain daily

(C) Changing the TCP port

(D) Using FTP instead of HTTP

Correct Answer: (A)

[EN] URI path (/v1, /v2), query params, and Accept headers are standard versioning strategies.

[HI] URI पाथ (/v1, /v2), क्वेरी पैरामीटर और Accept हेडर मानक वर्जनिंग रणनीतियां हैं।

Q16. Which HTTP status code indicates a conflict, such as a duplicate email during registration?

(कौन सा HTTP स्टेटस कोड टकराव (जैसे पंजीकरण के दौरान डुप्लिकेट ईमेल) को इंगित करता है?)

(A) 409 Conflict

(B) 401 Unauthorized

(C) 415 Unsupported Media Type

(D) 200 OK

Correct Answer: (A)

[EN] 409 Conflict signals that the request conflicts with the current state of the target resource.

[HI] 409 Conflict संकेत देता है कि अनुरोध लक्ष्य संसाधन की वर्तमान स्थिति से टकराता है।

Q17. Within REST API Design Best Practices: Methods, Status Codes & Versioning, which http method directly maps to: "Yes (Safe & Idempotent)"?

(REST API Design Best Practices: Methods, Status Codes & Versioning में कौन सा HTTP Method सीधे "Yes (Safe & Idempotent)" से संबंधित है?)

(A) PUT

(B) POST

(C) GET

(D) DELETE

Correct Answer: (C)

[EN] In REST API Design Best Practices: Methods, Status Codes & Versioning, 'GET' handles 'Yes (Safe & Idempotent)' (Retrieves resource; no side effects).

[HI] REST API Design Best Practices: Methods, Status Codes & Versioning में 'GET' का कार्य/विवरण 'Yes (Safe & Idempotent)' (Retrieves resource; no side effects) है।

Q18. Which option accurately describes 'POST' in REST API Design Best Practices: Methods, Status Codes & Versioning?

(REST API Design Best Practices: Methods, Status Codes & Versioning के संदर्भ में 'POST' की सही विशेषता कौन सी है?)

(A) Yes (Idempotent)

(B) No (Not Idempotent)

(C) Yes (Idempotent, removes resource)

(D) Yes (Safe & Idempotent)

Correct Answer: (B)

[EN] 'POST' provides 'No (Not Idempotent)' — key point: Creates new resource; returns 201 Created.

[HI] 'POST' का मुख्य विवरण 'No (Not Idempotent)' है (Creates new resource; returns 201 Created)।

Q19. In REST API Design Best Practices: Methods, Status Codes & Versioning, identify the correct parameter for the specification: "Yes (Idempotent)".

(REST API Design Best Practices: Methods, Status Codes & Versioning में "Yes (Idempotent)" विवरण किस विकल्प के लिए सही है?)

(A) POST

(B) DELETE

(C) PUT

(D) GET

Correct Answer: (C)

[EN] 'PUT' corresponds to 'Yes (Idempotent)' (Replaces entire resource at target URI).

[HI] 'PUT' का संबंध 'Yes (Idempotent)' (Replaces entire resource at target URI) से है।

Q20. Considering REST API Design Best Practices: Methods, Status Codes & Versioning, what key behavior defines 'DELETE'?

(REST API Design Best Practices: Methods, Status Codes & Versioning में 'DELETE' की मुख्य भूमिका या मान क्या है?)

(A) Yes (Idempotent)

(B) Yes (Safe & Idempotent)

(C) No (Not Idempotent)

(D) Yes (Idempotent, removes resource)

Correct Answer: (D)

[EN] 'DELETE' represents 'Yes (Idempotent, removes resource)' (Removes resource; often returns 204 No Content).

[HI] 'DELETE' का अर्थ/मान 'Yes (Idempotent, removes resource)' है (Removes resource; often returns 204 No Content)।

REST API Design Best Practices: Methods, Status Codes & Versioning — Exam FAQs

Q1: What is the main difference between REST and SOAP?

REST और SOAP में मुख्य अंतर क्या है?

[EN] REST is a lightweight architectural style using HTTP/JSON, whereas SOAP is a strict XML-based protocol with built-in WS-Security.

[HI] REST HTTP/JSON का उपयोग करने वाली एक हल्की आर्किटेक्चरल शैली है, जबकि SOAP एक सख्त XML-आधारित प्रोटोकॉल है।

Q2: When should I use PUT vs PATCH?

मुझे PUT बनाम PATCH का उपयोग कब करना चाहिए?

[EN] Use PUT when sending the complete updated resource; use PATCH when sending only the fields that changed.

[HI] पूर्ण अपडेटेड संसाधन भेजते समय PUT का उपयोग करें; केवल बदले हुए फ़ील्ड भेजते समय PATCH का उपयोग करें।

Q3: Why are REST APIs required to be stateless?

REST APIs का स्टेटलेस होना क्यों आवश्यक है?

[EN] Statelessness eliminates server-side session storage, making it easy to load-balance requests across any number of servers.

[HI] स्टेटलेसनेस सर्वर-साइड सेशन स्टोरेज को समाप्त करता है, जिससे किसी भी संख्या में सर्वरों पर लोड-बैलेंसिंग आसान हो जाती है।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)