API documentation • Route analysis • Endpoint discovery
RESTful APIs follow standardized patterns for resource management.
Standard HTTP methods for REST:
Resource Paths: Use nouns (users, posts), not verbs
RESTful design promotes consistent, predictable API structures.
RESTful APIs follow standardized design principles:
Standard HTTP methods for RESTful APIs:
Effective URL design patterns:
Representational State Transfer - architectural style for APIs.
GET, POST, PUT, PATCH, DELETE
Match actions to appropriate methods.
URLs should clearly identify resources.
Which HTTP method should be used to create a new user resource?
The correct answer is B) POST. POST is the standard HTTP method for creating new resources. It should be used when you want to create a new entity at a server-defined URI. GET is for retrieving resources, PUT is for updating entire resources, and DELETE is for removing resources.
Understanding HTTP methods is fundamental to RESTful design. Each method has a specific purpose and semantic meaning. POST creates new resources, PUT updates or creates at a specific URI, GET retrieves resources, PATCH modifies part of a resource, and DELETE removes resources.
POST: Creates new resource at server-defined URI
PUT: Updates resource at specific URI
GET: Retrieves resource
• POST is for creating new resources
• PUT is for updating existing resources
• Use appropriate method for intended action
• POST creates new resources
• PUT replaces entire resource
• PATCH updates partial resource
• Using GET for creating resources
• Using POST for updating resources
• Confusing PUT with POST
Which of the following URL patterns follows RESTful design principles for retrieving all users?
The correct answer is B) /users. RESTful design uses nouns to identify resources, not verbs. The URL /users represents the collection of users, and when accessed with GET, it returns all users. The other options use verbs (get, list) which violates REST principles.
RESTful URLs should represent resources, not actions. Using nouns instead of verbs creates a uniform interface. /users represents the resource collection, while /users/{id} represents a specific instance. HTTP methods define the action performed on these resources.
Resource: Thing identified by a URL
Collection Resource: Group of resources (e.g., /users)
Instance Resource: Single resource (e.g., /users/123)
• Use nouns, not verbs in URLs
• Use plural nouns for collections
• Use HTTP methods for actions
• Think in terms of resources, not actions
• Use plural nouns for collections
• Let HTTP methods define operations
• Using verbs in URLs
• Using singular nouns for collections
• Not following consistent patterns
Design the appropriate RESTful endpoints for managing blog posts and their comments. Include endpoints for retrieving all posts, creating a new post, retrieving a specific post, updating a post, deleting a post, retrieving comments for a specific post, and creating a comment for a specific post.
Appropriate RESTful endpoints:
GET /posts - Retrieve all posts
POST /posts - Create new post
GET /posts/{id} - Retrieve specific post
PUT /posts/{id} - Update entire post
DELETE /posts/{id} - Delete post
GET /posts/{postId}/comments - Retrieve comments for specific post
POST /posts/{postId}/comments - Create comment for specific post
This design follows REST principles using nouns for resources and appropriate HTTP methods for actions.
This demonstrates nested resource design. The comments are nested under posts (/posts/{id}/comments) to show the relationship between resources. This creates a clear hierarchy that reflects the data model while maintaining RESTful principles.
Nested Resources: Resources that belong to another resource
Resource Hierarchy: Parent-child relationships in URLs
Path Parameters: Variables in URL path segments
• Use nested paths for related resources
• Maintain consistent URL structure
• Use appropriate HTTP methods
• Model relationships in URL structure
• Use path parameters for IDs
• Keep URLs intuitive and predictable
• Not nesting related resources properly
• Using inconsistent URL patterns
• Not following HTTP method conventions
An e-commerce API needs endpoints for products, categories, and reviews. Products belong to categories, and reviews belong to products. Design the RESTful URL structure and explain the design decisions.
RESTful URL structure:
/categories - All categories
/categories/{id} - Specific category
/categories/{id}/products - Products in specific category
/products - All products
/products/{id} - Specific product
/products/{id}/reviews - Reviews for specific product
/reviews - All reviews (alternative access point)
Design decisions:
1. Use plural nouns for resource collections
2. Nest related resources to show relationships
3. Use path parameters for resource identifiers
4. Maintain consistent URL patterns
This demonstrates multi-level nesting for complex relationships. The hierarchy (categories → products → reviews) is reflected in the URL structure, making it intuitive for developers to understand the relationships between resources.
Multi-level Nesting: Resources nested multiple levels deep
Alternative Access Points: Multiple ways to access same resources
Resource Relationships: How resources relate to each other
• Reflect data relationships in URL structure
• Provide intuitive access patterns
• Consider performance implications of deep nesting
• Keep nesting reasonable (max 2-3 levels)
• Provide alternative access points
• Consider flat vs. nested structures
• Over-nesting resources
• Not reflecting business relationships
• Creating inconsistent URL patterns
Which of the following is the most appropriate use of query parameters in a RESTful API?
The answer is B) /users?filter=active&sort=name&page=2&limit=10. This uses query parameters appropriately for filtering, sorting, and pagination. Query parameters should be used for modifying how resources are retrieved, not for defining the operation (which should be handled by HTTP methods).
Query parameters should modify resource retrieval behavior, not define operations. Common uses include filtering, sorting, pagination, and field selection. The HTTP method defines the operation, while query parameters modify how that operation is performed.
Query Parameters: URL parameters for modifying retrieval
Filtering: Selecting subset of resources
Pagination: Breaking large results into pages
• Use query params for modifying retrieval
• Don't use query params for operations
• Use descriptive parameter names
• Use filter, sort, page, limit for common operations
• Keep parameter names consistent
• Document all query parameters
• Using query params for operations instead of methods
• Inconsistent parameter naming
• Not documenting query parameters
Q: What's the difference between PUT and PATCH methods in REST APIs?
A: The key differences are:
PUT is idempotent - making the same request multiple times should have the same effect as making it once. PATCH is not necessarily idempotent. Use PUT when you want to replace the entire resource, and PATCH when you want to update specific fields.
Q: How should I handle versioning in REST APIs?
A: Common versioning strategies:
URL versioning is most widely adopted as it's simple to implement and understand. Major version changes require new endpoints, while minor changes can be backward-compatible additions.