Knowledge / Computer Science and Engineering / REST APIs

REST APIs

Computer Science and Engineering (B.E./B.Tech) · Web, cloud and design · free study notes for exams, placements and interviews

In short

A REST API is a way for two programs to talk over HTTP by treating everything as a resource with a URL, and by using the plain HTTP verbs (GET, POST, PUT, PATCH, DELETE) to read and change it. It is the default integration style for Indian web and mobile products: UPI and NPCI interfaces, UIDAI/Aadhaar e-KYC, DigiLocker, GSTN, ONDC (beckn), Razorpay and Paytm payments, Swiggy/Zomato/Ola apps and almost every internal microservice all speak REST over JSON. Universities examine it under web technology, service-oriented architecture and cloud computing papers; placement rounds at TCS, Infosys, Wipro, Accenture, Cognizant, Zoho, Freshworks, Flipkart, Paytm and PhonePe almost always include "design an endpoint", "GET vs POST", "PUT vs PATCH" and "which status code would you return". A fresher who can name the right verb, the right status code and the right URI for a given requirement is usually judged job-ready on back-end basics.

Explained

What REST is, and the six constraints

HTTP methods: safety, idempotency, semantics

Status codes and error design

Designing URIs, collections and payloads

Cross-cutting concerns

Key points

Formulas and examples

pages = ⌈N / page_size⌉ ; offset for page p = (p − 1) × page_size (N = total records)
Sequential call latency T ≈ k × (RTT + server_time) ; k = number of round trips, RTT = round-trip time (s)
Little's Law: C = λ × W (C = concurrent in-flight requests, λ = throughput req/s, W = mean latency s)
Transfer time t = payload_bytes / bandwidth_bytes_per_second
Token bucket: time to serve a burst B = (B − C) / r for B > C (C = bucket capacity, r = refill rate req/s)
Reliability: success of a screen needing k calls = (1 − p)k ; with n attempts per call, p_eff = pn

1. Pagination arithmetic. A job portal holds N = 1,24,750 live listings; per_page = 50.

2. Chatty API (N+1 problem). A mobile app lists 20 jobs, then fetches each employer separately. RTT = 120 ms, server time = 20 ms per call, calls made sequentially.

3. Payload size, sparse fieldsets and compression. 100 listings × 1.8 KB = 180 KB of JSON; client on a 4 Mbps connection (4,000,000 / 8 = 500,000 B/s ≈ 488 KB/s; take 512 KB/s for a round figure of 2²⁹/2²⁰).

4. Rate limiting. Bucket capacity C = 100, refill r = 10 req/s; a scraper fires B = 250 requests at once.

5. Retries and screen reliability. Each API call fails with probability p = 0.02 (2%); a dashboard needs k = 4 sequential calls.

RequirementMethodURISuccess code
List jobs in Kochi, page 2GET/v1/jobs?city=Kochi&page=2200
Fetch one jobGET/v1/jobs/48213200 (or 404)
Post a new jobPOST/v1/jobs201 + Location
Replace a job fullyPUT/v1/jobs/48213200 / 204
Mark a job closedPATCH/v1/jobs/48213200
Withdraw a jobDELETE/v1/jobs/48213204
Apply to a jobPOST/v1/jobs/48213/applications201
Start a bulk importPOST/v1/imports202 + status URI
RESTSOAPGraphQLgRPC
StyleResources + HTTP verbsRPC with XML envelopeSingle endpoint, query languageRPC over HTTP/2
FormatJSON (any)XML onlyJSONProtocol Buffers (binary)
ContractOpenAPI (optional)WSDL (mandatory)SDL schema.proto file
Over/under-fetchingCommon; fix with fields/expandCommonClient asks for exact fieldsFixed messages
CachingNative HTTP cachingPoorHard (POST queries)Manual
StreamingLimited (SSE/polling)NoSubscriptionsBi-directional, native
Best forPublic, browser and mobile APIsLegacy banking/telecom, WS-SecurityRich UIs with varied data needsInternal, high-volume microservices
POST /v1/jobs/48213/applications HTTP/1.1
Host: api.abljobs.in
Content-Type: application/json
Authorization: Bearer <token>
Idempotency-Key: 9f2c1b7a-2026-10-29-001

{"student_id": 7741, "resume_id": 55120, "cover_note": "B.Tech CSE, 2027 batch"}

HTTP/1.1 201 Created
Location: /v1/applications/90312
ETag: "a1b2c3"
{"id": 90312, "status": "submitted", "created_at": "2026-10-29T09:15:00+05:30"}

HTTP/1.1 422 Unprocessable Content
Content-Type: application/problem+json
{"type":"/errors/validation","title":"Validation failed","status":422,
 "detail":"resume_id does not belong to student_id",
 "errors":[{"field":"resume_id","code":"ownership_mismatch"}],
 "request_id":"req_7c41e9"}

Where it is used

Interview questions

Common mistakes

Related topics

Open in the Knowledge reader →Find jobs →