REST, API Design & Web Flashcards

(15 cards)

1
Q

What is the difference between PathVariable and QueryParam in REST?

A

@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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are idempotent HTTP methods?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the categories of HTTP status codes?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between request parameters and path variables? When should each be used?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between the HTTP methods PUT and PATCH?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a CDN?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the OpenAPI Specification?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the REST constraints?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why choose REST when designing APIs? What factors influenced your decision?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When does an API become RESTful?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the Richardson Maturity Model? Can you briefly describe REST maturity levels?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is HATEOAS?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are best practices for designing REST APIs?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you manage different versions of a REST API?

A
  • URI versioning: Include version in the path (e.g., /api/v1/users).
  • Header versioning: Specify version in a custom HTTP header.
  • Query parameter versioning: Add version as a query parameter (e.g., /users?version=1).
  • Content negotiation: Use the Accept header to request a specific version.

Best practice: URI versioning is most common and visible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you implement pagination in RESTful services?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly