MCSD Web API and RESTful Services 2 — Questions and Answers
Question 1: What is content negotiation in ASP.NET Web API?
- Choosing the right database for the data
- The process of selecting the response format (JSON/XML) based on the client's Accept header (Correct answer)
- Encrypting the response body
- Compressing responses automatically
Correct answer: The process of selecting the response format (JSON/XML) based on the client's Accept header
Content negotiation selects the best response format by matching the client's `Accept` header with the server's supported formatters.
Question 2: In REST API design, what is the purpose of HATEOAS?
- Authenticating API consumers
- Providing hypermedia links in responses so clients can discover available actions (Correct answer)
- Encrypting API payloads
- Versioning API endpoints
Correct answer: Providing hypermedia links in responses so clients can discover available actions
HATEOAS (Hypermedia As The Engine Of Application State) includes links in responses to guide clients to related actions.
Question 3: What HTTP status code is returned when a requested resource does not exist in a REST API?
- 400 Bad Request
- 401 Unauthorized
- 404 Not Found (Correct answer)
- 500 Internal Server Error
Correct answer: 404 Not Found
HTTP 404 Not Found indicates the requested resource could not be located on the server.
Question 4: What does CORS stand for and why is it relevant to Web APIs?
- Content Optimization for REST Services — improves API performance
- Cross-Origin Resource Sharing — allows browsers to make API calls to a different domain (Correct answer)
- Centralized Object Routing System — routes API traffic
- Certificate Override for REST Services — manages SSL
Correct answer: Cross-Origin Resource Sharing — allows browsers to make API calls to a different domain
CORS (Cross-Origin Resource Sharing) is a browser security mechanism that Web APIs must configure to allow calls from different origins.
Question 5: Which approach to API versioning adds the version to the URL path?
- Header versioning
- Query string versioning
- URI versioning (Correct answer)
- Media type versioning
Correct answer: URI versioning
URI versioning embeds the version in the URL path (e.g., `/api/v1/products`), making it explicit and easily cacheable.
Question 6: What is the purpose of an API key in Web API security?
- Encrypts all traffic
- Identifies and authenticates the API consumer for access control and rate limiting (Correct answer)
- Generates JWT tokens automatically
- Manages CORS headers
Correct answer: Identifies and authenticates the API consumer for access control and rate limiting
API keys identify the caller, enabling the server to authenticate the consumer and apply rate limits or access controls.
What is content negotiation in ASP.NET Web API?