MCSD Web API and RESTful Services 1 — Questions and Answers
Question 1: What HTTP status code should a successful POST request that creates a resource return?
- 200 OK
- 204 No Content
- 201 Created (Correct answer)
- 202 Accepted
Correct answer: 201 Created
HTTP 201 Created indicates a new resource was successfully created, typically with a Location header pointing to it.
Question 2: In ASP.NET Web API, which attribute maps an action to HTTP GET requests?
- [HttpPost]
- [HttpGet] (Correct answer)
- [Route]
- [FromBody]
Correct answer: [HttpGet]
The `[HttpGet]` attribute explicitly marks a Web API action to respond to HTTP GET requests.
Question 3: What does REST stand for?
- Rapid Endpoint State Transfer
- Representational State Transfer (Correct answer)
- Remote Execution State Technology
- Resource Endpoint Service Technology
Correct answer: Representational State Transfer
REST stands for Representational State Transfer, an architectural style for designing networked APIs.
Question 4: Which HTTP verb is idempotent and used to fully replace an existing resource?
- POST
- PATCH
- PUT (Correct answer)
- DELETE
Correct answer: PUT
PUT replaces the entire resource at the target URL and is idempotent — calling it multiple times produces the same result.
Question 5: What does the `[FromBody]` attribute do in ASP.NET Web API?
- Reads a value from the query string
- Binds the action parameter from the HTTP request body (Correct answer)
- Specifies the response content type
- Reads a value from route data
Correct answer: Binds the action parameter from the HTTP request body
`[FromBody]` tells Web API to deserialize the HTTP request body (typically JSON) and bind it to the parameter.
Question 6: Which status code indicates the client sent a request with invalid data in a REST API?
- 401 Unauthorized
- 403 Forbidden
- 404 Not Found
- 400 Bad Request (Correct answer)
Correct answer: 400 Bad Request
HTTP 400 Bad Request indicates the server cannot process the request due to client-side invalid input.
What HTTP status code should a successful POST request that creates a resource return?