What is the difference between PathVariable and QueryParam in REST?
@PathVariable:
* Extracts values from the URI path (e.g., /users/{id}).
* Used for identifying specific resources.
@RequestParam:
* Extracts values from query parameters (e.g., /users?active=true).
* Used for filtering, sorting, or optional parameters.
What are idempotent HTTP methods?
HTTP methods that can be called multiple times with the same result and no additional side effects.
Examples:
* GET: Retrieve data (no change).
* PUT: Update/replace resource (same update = same result).
* DELETE: Remove resource (repeated deletes = same state).
* HEAD, OPTIONS, TRACE: Also idempotent.
What are the categories of HTTP status codes?
1xx (Informational): Request received, continuing process.
2xx (Success): Request successfully received, understood, and accepted.
3xx (Redirection): Further action needed to complete the request.
4xx (Client Error): Request has bad syntax or cannot be fulfilled.
5xx (Server Error): Server failed to fulfill a valid request.
What is the difference between request parameters and path variables? When should each be used?
Path variables:
* Part of the URL path (e.g., /users/{id}).
* Used to identify specific resources.
Request parameters:
* Appended to the URL as query strings (e.g., /users?active=true).
* Used for filtering, sorting, or optional data.
What is the difference between the HTTP methods PUT and PATCH?
PUT:
* Replaces the entire resource with the provided data.
* Idempotent—repeating the request has the same effect.
PATCH:
* Updates only the specified fields of a resource.
* May not be idempotent, depending on implementation.
What is a CDN?
CDN (Content Delivery Network): A distributed network of servers that delivers web content (like images, videos, scripts) to users based on their geographic location.
Benefits:
* Reduces latency and load times.
* Improves availability and reliability.
* Offloads traffic from the origin server.
What is the OpenAPI Specification?
A standard, language-agnostic format for describing RESTful APIs.
Defines endpoints, request/response formats, parameters, authentication, and more—usually in YAML or JSON.
Enables automatic API documentation, client/server code generation, and easier API integration.
What are the REST constraints?
Client-Server: Separation of concerns between client and server.
Stateless: Each request contains all information needed; no session state on server.
Cacheable: Responses must define themselves as cacheable or not.
Uniform Interface: Standardized way to interact with resources (e.g., URIs, HTTP methods).
Layered System: Architecture can have multiple layers (e.g., proxies, gateways).
Code on Demand (optional): Servers can send executable code to clients.
Why choose REST when designing APIs? What factors influenced your decision?
Simplicity: Easy to understand and use with standard HTTP methods.
Scalability: Statelessness and caching support horizontal scaling.
Interoperability: Language-agnostic; works with any client that can make HTTP requests.
Widespread adoption: Broad tool and library support.
Flexibility: Can be used for web, mobile, and IoT applications.
When does an API become RESTful?
An API is RESTful when it adheres to REST constraints:
* Uses standard HTTP methods (GET, POST, PUT, DELETE, etc.).
* Has resource-based URIs (e.g., /users/{id}).
* Is stateless—each request contains all necessary information.
* Supports caching where appropriate.
* Provides a uniform interface for clients.
* Optionally, supports layered architecture and code on demand.
What is the Richardson Maturity Model? Can you briefly describe REST maturity levels?
Richardson Maturity Model: A way to measure how RESTful an API is, with four levels:
* Level 0: Single endpoint, uses HTTP as a transport for remote calls (e.g., XML-RPC).
* Level 1: Multiple endpoints, resources are introduced (e.g., /users, /orders).
* Level 2: Uses proper HTTP methods (GET, POST, PUT, DELETE) and status codes.
* Level 3: Adds HATEOAS (Hypermedia as the Engine of Application State)—responses include links to related actions/resources.
What is HATEOAS?
HATEOAS stands for Hypermedia as the Engine of Application State.
It’s a REST constraint where API responses include links to related resources or actions, allowing clients to navigate the API dynamically.
Example: A /users/1 response might include links to update or delete the user.
What are best practices for designing REST APIs?
Use clear, resource-based URIs (e.g., /users/{id}).
Use appropriate HTTP methods (GET, POST, PUT, DELETE, etc.).
Return proper HTTP status codes.
Support filtering, sorting, and pagination for collections.
Use consistent naming and versioning.
Provide meaningful error messages.
Secure APIs with authentication and authorization.
Document the API (e.g., with OpenAPI/Swagger).
How do you manage different versions of a REST API?
Best practice: URI versioning is most common and visible.
How do you implement pagination in RESTful services?
Use query parameters like page, size, limit, and offset (e.g., /users?page=2&size=20).
Return paginated data along with metadata (e.g., total items, total pages, current page).
Optionally, include navigation links (next, previous) in the response.