0% found this document useful (0 votes)
7 views8 pages

REST API Interview Questions

The document provides a comprehensive overview of REST API concepts, including definitions, HTTP methods, endpoints, resources, and data formats like JSON. It covers key topics such as authentication, authorization, middleware, CORS, API versioning, and rate limiting, along with comparisons to SOAP and GraphQL. Additionally, it includes practical examples and best practices for securing REST APIs and optimizing performance.

Uploaded by

Suthar Dhruvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

REST API Interview Questions

The document provides a comprehensive overview of REST API concepts, including definitions, HTTP methods, endpoints, resources, and data formats like JSON. It covers key topics such as authentication, authorization, middleware, CORS, API versioning, and rate limiting, along with comparisons to SOAP and GraphQL. Additionally, it includes practical examples and best practices for securing REST APIs and optimizing performance.

Uploaded by

Suthar Dhruvi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

✅ REST API Interview Questions & Answers

🔥 1. What is a REST API?

Answer (Easy Explanation):


REST API is a way for two systems to communicate over the internet using HTTP.
Client sends a request → Server sends a response (mostly JSON).

Example:
Frontend → (REST API) → Backend.

🔥 2. What does REST stand for?

Answer:
Representational
State
Transfer

Meaning: Server sends data in a representational format (JSON, XML).

🔥 3. What are HTTP Methods?

Methods used to perform operations:

Method Meaning

GET Read data

POST Create data

PUT Update entire data

PATCH Update partial data

DELETE Delete data

🔥 4. What is the difference between PUT and PATCH?

PUT PATCH

Replaces entire resource Updates only specific fields

Full update Partial update


🔥 5. What is an Endpoint?

Simple:
An endpoint is a URL where your API lives.

Example:

GET /users

POST /login

🔥 6. What is a Resource?

A resource is anything you handle via API:


users, products, orders, students, images…

🔥 7. What is JSON? Why used?

JSON is JavaScript Object Notation.


Used because it is lightweight and easy to parse.

Example:

"name": "John",

"age": 25

🔥 8. What is the Status Code? Explain types.

Status codes tell the result of API call:

Code Meaning

200 OK

201 Created

400 Bad request

401 Unauthorized

404 Not found


Code Meaning

500 Server error

🔥 9. What is Authentication?

Verifying who the user is.

Example:
Login using username/password, token, JWT.

🔥 10. What is Authorization?

Permissions – What a user can access.

Example:
Admin can delete users, normal users cannot.

🔥 11. What is JWT?

JWT = JSON Web Token


Used for secure login and session handling.

Example Token:

[Link]

🔥 12. What is Middleware in REST API ([Link])?

Middleware runs between request and response.

Example:
Authentication check
Logging
Validation

[Link]((req, res, next) => {

[Link]("Request received");

next();

});
🔥 13. What is CORS?

CORS = Cross-Origin Resource Sharing


Allows frontend from different domain to call API.

🔥 14. What is API Versioning?

Different versions of same API:

/api/v1/users

/api/v2/users

Useful when updating features without breaking old apps.

🔥 15. What is Rate Limiting?

Controlling how many requests a user can send.

Used to stop overload or attacks.

🔥 16. What is Idempotency?

Idempotent operations = same result every time you call.

Examples:
✔ GET → Always same result
✔ PUT → Same result
❌ POST → NOT idempotent (creates new each time)

🔥 17. What is Pagination?

Breaking large data into small chunks.

Example:

GET /users?page=1&limit=10

🔥 18. What is REST vs SOAP?


REST SOAP

Uses JSON Uses XML

Lightweight Heavy

Fast Slow

Simple Complex

🔥 19. What is REST vs GraphQL?

REST GraphQL

Fixed endpoints Single endpoint

Returns full data Returns only required data

Over-fetching possible No over-fetching

🔥 20. What is CRUD?

CRUD = Create, Read, Update, Delete


Implemented using REST methods:

Operation REST Method

Create POST

Read GET

Update PUT/PATCH

Delete DELETE

🔥 21. What is Headers in REST API?

Headers contain extra information.

Example:

Content-Type: application/json

Authorization: Bearer token

🔥 22. What is Request Body?


Data sent along with POST/PUT/PATCH.

Example:

"name": "Dhruvi"

🔥 23. What is Query Parameter?

Used for filtering or pagination.

Example:

GET /products?category=mobile&price=10000

🔥 24. What is Path Parameter?

Used to pass ID.

Example:

GET /users/101

🔥 25. What is API Gateway?

A single entry point for multiple services.


Used in microservice architecture.

🔥 26. What is RESTful Routing?

Rules for creating proper API URLs.

✔ Nouns, not verbs


❌ /getAllUsers
✔ /users

🔥 27. What is HATEOAS?

Hypermedia as the Engine of Application State


REST principle where API responses contain links.
Example:

"user": "John",

"links": {

"orders": "/users/1/orders"

🔥 28. How to secure REST API?

✔ JWT tokens
✔ HTTPS
✔ CORS
✔ API rate limits
✔ Input validation
✔ OAuth

🔥 29. What is Response Time?

Time taken by server to return data.


Should be low (optimized API).

🔥 30. What is Postman?

A tool used to test REST APIs easily.

🎯 Bonus: REST API Example ([Link] + Express)

[Link]

const express = require("express");

const app = express();

[Link]([Link]());
// READ

[Link]("/users", (req, res) => {

[Link]({ message: "All users" });

});

// CREATE

[Link]("/users", (req, res) => {

[Link](201).json({ message: "User created" });

});

// UPDATE

[Link]("/users/:id", (req, res) => {

[Link]({ message: "User updated" });

});

// DELETE

[Link]("/users/:id", (req, res) => {

[Link]({ message: "User deleted" });

});

[Link](5000, () => [Link]("server running"));

You might also like