Unit 6: Asp.Net With Web API - Practice Quiz
1 What does REST stand for?
2 Which HTTP method is commonly used to retrieve a resource in a REST API?
3 In a RESTful API, what does a URI normally identify?
4 What is ASP.NET Web API mainly used to build?
5 Which data format is commonly returned by an ASP.NET Web API?
6 Which base class is commonly used for controllers in classic ASP.NET Web API?
7 What is the main responsibility of a Web API controller?
8 Which class is typically used to represent data exchanged by a Web API?
9 Which development environment is commonly used to create an ASP.NET Web API project?
10 In which project folder are Web API controller classes commonly stored?
11 What is a primary key used for in a database table?
12 What does a database connection string contain?
13 Which technology is commonly used to access a database from an ASP.NET application using .NET objects?
14 What does the letter C represent in CRUD?
15 Which HTTP method is commonly used to create a new resource?
16 Which HTTP method is commonly used to update an existing resource completely?
17 Which HTTP method is used to remove a resource?
18 What is Postman mainly used for during Web API development?
19 Where can a developer view the data returned by an API in Postman?
20 Which route template is commonly used as the default convention-based Web API route?
21 A shopping API stores each user's previous request data on the server so that later requests can be processed. Which REST constraint is being violated?
22 A client sends the same request several times to replace product 10 with the same representation. Which HTTP method is most appropriate because the operation is expected to be idempotent?
23
An ASP.NET Web API action returns a C# Product object. How is the response format normally selected when both JSON and XML formatters are available?
Accept header
24
A controller action must return either 200 OK, 404 Not Found, or 400 Bad Request depending on validation and lookup results. Which return type is most suitable in classic ASP.NET Web API?
JsonMediaTypeFormatter
DbSet<Product>
IHttpActionResult
HttpRequestMessage
25
An entity contains internal fields such as CostPrice and SupplierNotes, but API clients should receive only Id, Name, and SellingPrice. What is the most maintainable approach?
26
A Web API action performs an asynchronous Entity Framework query using ToListAsync(). Which action declaration best avoids blocking the request thread?
public Product GetProducts()
public async Task<IHttpActionResult> GetProducts()
public void GetProducts()
public DbSet<Product> GetProducts()
27
A newly created classic ASP.NET Web API project contains WebApiConfig.Register, but none of its routes are active at runtime. Which startup statement should be checked?
BundleTable.EnableOptimizations = true;
RouteTable.Routes.Clear();
Database.SetInitializer(null);
GlobalConfiguration.Configure(WebApiConfig.Register);
28
Using the conventional route api/{controller}/{id}, which controller is selected for a GET request to /api/products/12?
ProductsController
ProductsApiController
ProductController
ProductServiceController
29
In Entity Framework, a StoreContext class derives from DbContext. Which property is normally added to query and save Product entities?
public IQueryable Products { get; set; }
public DbSet<Product> Products { get; set; }
public List<Product> Products { get; set; }
public DataTable Products { get; set; }
30
A developer adds a required Category property to the Product entity in a code-first project. What should normally be done to update an existing database schema?
31
A GET /api/products/50 action searches the database, but product 50 does not exist. Which response is most appropriate?
200 OK with an empty object
404 Not Found
201 Created with no body
500 Internal Server Error
32 After successfully inserting a new product, which response best follows REST conventions by providing both the created representation and its URI?
Redirect(product.Name)
CreatedAtRoute(routeName, values, product)
Ok(product)
NotFound()
33
A client sends PUT /api/products/8, but the JSON body contains an Id value of 11. What should the API normally do before updating the record?
34
A DELETE /api/products/9 operation successfully removes product 9 and does not need to return a representation. Which response is most suitable?
405 Method Not Allowed
201 Created
204 No Content
304 Not Modified
35 A valid JSON body sent from Postman reaches the API as an unsupported media type because Postman labels the body as plain text. Which header should be set?
Authorization: application/json
Cache-Control: application/json
Accept-Encoding: application/json
Content-Type: application/json
36 While testing content negotiation in Postman, a developer wants the API to return XML without changing the controller. Which request header should be used?
Host: application/xml
Accept: application/xml
Content-Length: application/xml
Location: application/xml
37
Given the conventional route api/{controller}/{id} with id optional, which URL supplies ProductsController with an ID value of 7?
/api/products?id/name/7
/products/api/7
/api/products/7
/api/7/products
38
An action is declared with [Route("api/products/{id:int}")]. Which request matches this attribute route?
GET /api/products/25.5
GET /api/products/twenty
GET /api/products/25
GET /api/products/all-items
39
Actions decorated with [Route] return 404 Not Found, but conventional routes in the same project work correctly. Which configuration call is most likely missing?
config.Formatters.Clear();
config.Routes.Clear();
config.MapHttpAttributeRoutes();
config.EnsureInitialized();
40
A controller has [RoutePrefix("api/orders")], and one of its actions has [Route("{id:int}")]. Which URL matches that action for order 15?
/api/15/orders
/orders/api/15
/api/orders/15
/api/orders/id/15
41
A client sends POST /payments and times out before receiving the response. The server may already have created the payment. Which design most reliably allows the client to retry without creating a duplicate payment?
POST only after clearing all client-side HTTP cache entries
POST to GET using the same representation
42
A resource was retrieved with ETag: "v8". Before an update is submitted, another client changes the resource to version v9. What should the server return when the original client sends PUT with If-Match: "v8"?
200 OK, because PUT replaces the current representation
412 Precondition Failed, because the supplied validator no longer matches
409 Conflict, because every concurrent update uses that status
304 Not Modified, because the cached representation is stale
43
Consider this ASP.NET Web API 2 action:
public IHttpActionResult Put(int id, ProductUpdate update)
It is invoked through PUT /api/products/7 with a JSON request body. Under the default parameter-binding rules, where are the values obtained?
id is read from the body, while update is read from the URI
id and update are read exclusively from the request body
id and update are read exclusively from route variables
id is read from the URI, while update is read from the body
44
An ASP.NET Web API service has both JSON and XML formatters enabled. A request includes Accept: application/json;q=0.6, application/xml;q=0.9. The returned model can be serialized by either formatter. Which representation should content negotiation select?
45
Two DelegatingHandler instances, AuditHandler and CompressionHandler, are added to config.MessageHandlers in that order. Assuming both call base.SendAsync, what is the effective pipeline order?
46
A request DTO contains [Required] and [Range] annotations. An ASP.NET Web API 2 action receives a DTO that violates both annotations, but the action immediately saves it. Why can this still occur under the default behavior?
SaveChanges
ModelState, but the action must handle invalid state
47
A project uses both [Route] attributes and a broad conventional route such as api/{controller}/{id}. Which registration sequence is the standard way to ensure attribute routes are considered before conventional routes?
MapHttpAttributeRoutes() before calling MapHttpRoute(...)
MapHttpRoute(...) before calling MapHttpAttributeRoutes()
MapHttpAttributeRoutes() only inside each API controller
MapHttpRoute(...) once for every method carrying [Route]
48
A class contains valid public methods named Get and Post, but requests never reach it under the default ASP.NET Web API 2 controller selector. Which declaration is eligible for normal controller discovery?
internal class InventoryController : ApiController
public abstract class InventoryController : ApiController
public class InventoryController : ApiController
public class InventoryService : ApiController
49
A PUT endpoint accepts an Entity Framework entity directly from JSON and marks it as Modified. Attackers can include properties such as IsAdministrator that the UI never displays. Which approach best mitigates this overposting vulnerability?
AsNoTracking() before marking every submitted property as modified
50
An endpoint enumerates 500 orders and accesses order.Customer.Name inside a loop while lazy loading is enabled. Monitoring shows 501 SQL queries. Which change most directly eliminates this N+1 pattern while returning only required data?
AsEnumerable() before accessing customers
DbContext for each order returned by the endpoint
SaveChanges() before enumerating the collection of orders
51
An entity uses a SQL rowversion column for optimistic concurrency. The API exposes that version as an ETag and requires If-Match on updates. An Entity Framework concurrency exception confirms that the stored version changed. Which response best matches this API contract?
400 Bad Request, because the submitted entity failed model validation
404 Not Found, because the requested version no longer exists
412 Precondition Failed, because the update condition became false
500 Internal Server Error, because concurrency is a database exception
52
After successfully inserting a product, an ASP.NET Web API 2 action must return 201 Created, include the new representation, and generate a Location header from the named route GetProduct. Which result is most appropriate?
RedirectToRoute("GetProduct", new { id = product.Id })
CreatedAtRoute("GetProduct", new { id = product.Id }, product)
Ok(product)
StatusCode(HttpStatusCode.NoContent)
53
A client sends PUT /api/products/12 with a body whose Id is 18. The endpoint treats PUT as replacement of the resource identified by the URI. What is the safest response?
18 because the body is more authoritative than the URI
12 while silently replacing the body's Id with 12
400 Bad Request because the URI and representation identify different resources
PUT is required to duplicate representations
54
The first DELETE /api/items/9 removes the item and returns 204 No Content. A second identical request returns 404 Not Found. Does this violate the idempotence requirement of DELETE?
DELETE is defined as a safe method without side effects
404 Not Found
55
A Postman request sends syntactically valid JSON, but the header is Content-Type: text/plain. The action expects a complex DTO from the body, and no text formatter can deserialize it. Which change addresses the likely 415 Unsupported Media Type response?
Authorization header
Accept: application/json without changing the body type
Cache-Control: no-cache to disable cached media types
Content-Type: application/json for the request body
56
A GET request in Postman returns the header ETag: "7". To test a conditional update using that exact strong validator, which request header should be sent with the subsequent PUT?
If-None-Match: 7
If-Unmodified-Since: 7
Last-Modified: "7"
If-Match: "7"
57
To reproduce an optimistic-concurrency conflict in Postman, a tester captures one ETag and sends two updates using the same If-Match value. Assuming the first update succeeds and changes the ETag, what should a correctly implemented second update return?
201 Created, because the second update creates a new entity version
204 No Content, because identical preconditions make requests idempotent
304 Not Modified, because the request contains an outdated validator
412 Precondition Failed, because the original ETag is now stale
58
Two actions differ only by query-string intent: one should handle /api/search?name=ada, and the other should handle /api/search?id=4. Why can conventional route templates alone not reliably select between them?
POST requests
59
A controller declares [Route("api/orders/{id:int}")] and [Route("api/orders/{status}")] on different GET actions. Which action is selected for GET /api/orders/42 under attribute-routing precedence?
{id:int} action, because a matching constrained parameter is more specific
{status} action, because unconstrained strings accept all route values
60
A controller has [RoutePrefix("api/customers")], but one action is decorated with [Route("~/api/accounts/{id:int}")]. Which URL matches that action for an identifier of 5?
/api/customers/api/accounts/5
/accounts/api/customers/5
/api/customers/accounts/5
/api/accounts/5
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →