Test your knowledge of API design essentials, including best practices around resources, data validation, versioning, and ensuring idempotency for robust model endpoints. This quiz helps you review the core principles needed for effective API development and management.
Resource Naming in APIs
Which of the following is the recommended naming convention for an API endpoint representing a set of book resources?
- GET /retrieve_books
- GET /GetBooks
- GET /BookList
- GET /books
Input Validation
Why is input validation important when designing a POST endpoint that accepts user data?
- It ensures only valid and expected data is processed by the server.
- It guarantees the client will receive results in real-time.
- It helps increase server storage capacity.
- It makes the API run faster by skipping unnecessary checks.
Handling Resource Identifiers
Given the endpoint /users/{id}, what does the {id} typically represent in RESTful APIs?
- The unique identifier for a specific user resource
- The type of user account
- The timestamp of the API request
- The API version number
Versioning Best Practices
Which option shows the preferred way to specify an API version in the endpoint path?
- /orders/v_1
- /v1/orders
- /orders/version1
- /orders?ver=1
Idempotency Definition
If a client sends the same PUT request multiple times to /users/42 with the same data, what property ensures the result remains unchanged?
- Latency
- Concurrency
- Redundancy
- Idempotency
Resource vs. Action-Based Endpoints
Why should you prefer resource-based endpoints like /payments over action-based endpoints such as /processPayment in RESTful APIs?
- Resource-based endpoints are more predictable and align with REST principles.
- Resource-based endpoints require more server resources.
- Action-based endpoints automatically handle authentication.
- Action-based endpoints are always faster.
HTTP Methods and Safe Operations
Which HTTP method is considered safe and is typically used to retrieve data without modifying server state?
- GET
- POST
- DELETE
- PATCH
Data Validation on Model Endpoints
When receiving a request to /predict with a required field 'input', what should the server return if 'input' is missing?
- 500 Internal Server Error
- 400 Bad Request with a clear error message
- 200 OK with an empty response
- 403 Forbidden
API Version Deprecation
What is a good practice when planning to deprecate an old version of an API endpoint (e.g., /v1/models)?
- Remove the old version without warning
- Limit the API rate without telling clients
- Change the endpoint name with no explanation
- Provide advance notice and clear documentation to clients
Ensuring Idempotency for POST Requests
Which approach can help make POST /orders idempotent if clients might retry requests due to network errors?
- Require clients to send a unique idempotency key with each request
- Disable validation for incoming requests
- Change POST to GET for all write operations
- Let duplicate orders be created without restrictions