Unit 6: Asp.Net With Web API - Practice Quiz

INT402 — Modern Web Programming Tools And Techniques 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What does REST stand for?

Introduction to REST Easy
A. Resource Exchange Standard Type
B. Representational State Transfer
C. Remote Execution Service Tool
D. Responsive Server Transfer

2 Which HTTP method is commonly used to retrieve a resource in a REST API?

Introduction to REST Easy
A. GET
B. PUT
C. POST
D. DELETE

3 In a RESTful API, what does a URI normally identify?

Introduction to REST Easy
A. A compiler
B. A resource
C. A programming loop
D. A database driver

4 What is ASP.NET Web API mainly used to build?

Introduction to ASP.NET Web API Easy
A. Desktop applications
B. Operating systems
C. Device drivers
D. HTTP services

5 Which data format is commonly returned by an ASP.NET Web API?

Introduction to ASP.NET Web API Easy
A. JSON
B. MP3
C. PSD
D. EXE

6 Which base class is commonly used for controllers in classic ASP.NET Web API?

Introduction to ASP.NET Web API Easy
A. PageController
B. FormController
C. ViewController
D. ApiController

7 What is the main responsibility of a Web API controller?

Building ASP.NET Web API Easy
A. Designing database tables
B. Compiling JavaScript files
C. Handling HTTP requests
D. Creating image resources

8 Which class is typically used to represent data exchanged by a Web API?

Building ASP.NET Web API Easy
A. Route class
B. Style class
C. Script class
D. Model class

9 Which development environment is commonly used to create an ASP.NET Web API project?

Creating First Web API Project Easy
A. Microsoft Excel
B. Adobe Photoshop
C. VLC Media Player
D. Visual Studio

10 In which project folder are Web API controller classes commonly stored?

Creating First Web API Project Easy
A. Content
B. Images
C. Controllers
D. Scripts

11 What is a primary key used for in a database table?

Creating Database for Web API Easy
A. Uniquely identifying each row
B. Formatting every column
C. Sorting all records automatically
D. Encrypting the entire table

12 What does a database connection string contain?

Creating Database for Web API Easy
A. Controller routing attributes
B. Database connection information
C. Web page styling rules
D. Client validation messages

13 Which technology is commonly used to access a database from an ASP.NET application using .NET objects?

Creating Database for Web API Easy
A. Postman
B. Bootstrap
C. HTML
D. Entity Framework

14 What does the letter C represent in CRUD?

ASP.NET Web API CRUD Operations Easy
A. Compile
B. Create
C. Connect
D. Configure

15 Which HTTP method is commonly used to create a new resource?

ASP.NET Web API CRUD Operations Easy
A. GET
B. HEAD
C. DELETE
D. POST

16 Which HTTP method is commonly used to update an existing resource completely?

ASP.NET Web API CRUD Operations Easy
A. DELETE
B. GET
C. PUT
D. POST

17 Which HTTP method is used to remove a resource?

ASP.NET Web API CRUD Operations Easy
A. GET
B. DELETE
C. PUT
D. POST

18 What is Postman mainly used for during Web API development?

Testing Web API Using Postman Easy
A. Compiling server-side programs
B. Sending and testing HTTP requests
C. Designing web page layouts
D. Creating relational database tables

19 Where can a developer view the data returned by an API in Postman?

Testing Web API Using Postman Easy
A. Request URL
B. Response body
C. Workspace name
D. Method list

20 Which route template is commonly used as the default convention-based Web API route?

Routing: Convention and Attribute Routing Easy
A. api/{controller}/{id}
B. view/{page}/{name}
C. site/{folder}/{file}
D. data/{table}/{column}

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?

Introduction to REST Medium
A. Layered system
B. Uniform interface
C. Cacheability
D. Statelessness

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?

Introduction to REST Medium
A. PATCH
B. POST
C. PUT
D. CONNECT

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?

Introduction to ASP.NET Web API Medium
A. From the action method's name
B. From the client's Accept header
C. From the database column types
D. From the controller's file extension

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?

Introduction to ASP.NET Web API Medium
A. JsonMediaTypeFormatter
B. DbSet<Product>
C. IHttpActionResult
D. 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?

Building ASP.NET Web API Medium
A. Return the database entity unchanged
B. Create and return a dedicated DTO
C. Remove the fields from the database
D. Store the hidden fields as null

26 A Web API action performs an asynchronous Entity Framework query using ToListAsync(). Which action declaration best avoids blocking the request thread?

Building ASP.NET Web API Medium
A. public Product GetProducts()
B. public async Task<IHttpActionResult> GetProducts()
C. public void GetProducts()
D. 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?

Creating First Web API Project Medium
A. BundleTable.EnableOptimizations = true;
B. RouteTable.Routes.Clear();
C. Database.SetInitializer(null);
D. GlobalConfiguration.Configure(WebApiConfig.Register);

28 Using the conventional route api/{controller}/{id}, which controller is selected for a GET request to /api/products/12?

Creating First Web API Project Medium
A. ProductsController
B. ProductsApiController
C. ProductController
D. ProductServiceController

29 In Entity Framework, a StoreContext class derives from DbContext. Which property is normally added to query and save Product entities?

Creating Database for Web API Medium
A. public IQueryable Products { get; set; }
B. public DbSet<Product> Products { get; set; }
C. public List<Product> Products { get; set; }
D. 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?

Creating Database for Web API Medium
A. Rename the connection string and retry
B. Create a migration and update the database
C. Add a new route for the property
D. Restart IIS and rebuild the controller

31 A GET /api/products/50 action searches the database, but product 50 does not exist. Which response is most appropriate?

ASP.NET Web API CRUD Operations Medium
A. 200 OK with an empty object
B. 404 Not Found
C. 201 Created with no body
D. 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?

ASP.NET Web API CRUD Operations Medium
A. Redirect(product.Name)
B. CreatedAtRoute(routeName, values, product)
C. Ok(product)
D. 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?

ASP.NET Web API CRUD Operations Medium
A. Reject the request as inconsistent
B. Ignore the URI and update product 11
C. Update both product 8 and product 11
D. Create a new product with ID 8

34 A DELETE /api/products/9 operation successfully removes product 9 and does not need to return a representation. Which response is most suitable?

ASP.NET Web API CRUD Operations Medium
A. 405 Method Not Allowed
B. 201 Created
C. 204 No Content
D. 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?

Testing Web API Using Postman Medium
A. Authorization: application/json
B. Cache-Control: application/json
C. Accept-Encoding: application/json
D. 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?

Testing Web API Using Postman Medium
A. Host: application/xml
B. Accept: application/xml
C. Content-Length: application/xml
D. Location: application/xml

37 Given the conventional route api/{controller}/{id} with id optional, which URL supplies ProductsController with an ID value of 7?

Routing: Convention and Attribute Routing Medium
A. /api/products?id/name/7
B. /products/api/7
C. /api/products/7
D. /api/7/products

38 An action is declared with [Route("api/products/{id:int}")]. Which request matches this attribute route?

Routing: Convention and Attribute Routing Medium
A. GET /api/products/25.5
B. GET /api/products/twenty
C. GET /api/products/25
D. 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?

Routing: Convention and Attribute Routing Medium
A. config.Formatters.Clear();
B. config.Routes.Clear();
C. config.MapHttpAttributeRoutes();
D. 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?

Routing: Convention and Attribute Routing Medium
A. /api/15/orders
B. /orders/api/15
C. /api/orders/15
D. /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?

Introduction to REST Hard
A. Add a unique timestamp to every retry so the server recognizes the request
B. Send a client-generated idempotency key that the server stores with the result
C. Repeat the POST only after clearing all client-side HTTP cache entries
D. Change the retry request from 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"?

Introduction to REST Hard
A. 200 OK, because PUT replaces the current representation
B. 412 Precondition Failed, because the supplied validator no longer matches
C. 409 Conflict, because every concurrent update uses that status
D. 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?

Introduction to ASP.NET Web API Hard
A. id is read from the body, while update is read from the URI
B. Both id and update are read exclusively from the request body
C. Both id and update are read exclusively from route variables
D. 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?

Introduction to ASP.NET Web API Hard
A. XML, because XML is selected whenever multiple formatters are available
B. JSON, because the two media types represent equivalent resources
C. JSON, because ASP.NET Web API always prioritizes its JSON formatter
D. XML, because it has the higher acceptable quality factor

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?

Building ASP.NET Web API Hard
A. Request: Audit → Compression → Controller; response: Controller → Compression → Audit
B. Request: Controller → Audit → Compression; response: Compression → Audit → Controller
C. Request: Audit → Controller → Compression; response: Compression → Controller → Audit
D. Request: Compression → Audit → Controller; response: Controller → Audit → Compression

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?

Building ASP.NET Web API Hard
A. Data annotations are ignored unless every DTO property is a value type
B. Data annotations execute only when an XML formatter is selected
C. Validation occurs only after the database context calls SaveChanges
D. Validation populates 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?

Creating First Web API Project Hard
A. Call MapHttpAttributeRoutes() before calling MapHttpRoute(...)
B. Call MapHttpRoute(...) before calling MapHttpAttributeRoutes()
C. Call MapHttpAttributeRoutes() only inside each API controller
D. Call 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?

Creating First Web API Project Hard
A. internal class InventoryController : ApiController
B. public abstract class InventoryController : ApiController
C. public class InventoryController : ApiController
D. 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?

Creating Database for Web API Hard
A. Accept a dedicated update DTO and copy only permitted fields to the loaded entity
B. Serialize the submitted entity to XML before attaching it to the context
C. Attach the submitted entity and exclude only its primary key from modification
D. Call 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?

Creating Database for Web API Hard
A. Project orders and customer names into a DTO within the LINQ query
B. Convert the order query to AsEnumerable() before accessing customers
C. Create a separate DbContext for each order returned by the endpoint
D. Call 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?

Creating Database for Web API Hard
A. 400 Bad Request, because the submitted entity failed model validation
B. 404 Not Found, because the requested version no longer exists
C. 412 Precondition Failed, because the update condition became false
D. 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?

ASP.NET Web API CRUD Operations Hard
A. RedirectToRoute("GetProduct", new { id = product.Id })
B. CreatedAtRoute("GetProduct", new { id = product.Id }, product)
C. Ok(product)
D. 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?

ASP.NET Web API CRUD Operations Hard
A. Update product 18 because the body is more authoritative than the URI
B. Update product 12 while silently replacing the body's Id with 12
C. Return 400 Bad Request because the URI and representation identify different resources
D. Create both products because 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?

ASP.NET Web API CRUD Operations Hard
A. No, because DELETE is defined as a safe method without side effects
B. Yes, because an idempotent method cannot return 404 Not Found
C. No, because the resource state after either request remains deleted
D. Yes, because every repeated request must return the same status code

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?

Testing Web API Using Postman Hard
A. Move the JSON document into the Authorization header
B. Set Accept: application/json without changing the body type
C. Add Cache-Control: no-cache to disable cached media types
D. Set 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?

Testing Web API Using Postman Hard
A. If-None-Match: 7
B. If-Unmodified-Since: 7
C. Last-Modified: "7"
D. 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?

Testing Web API Using Postman Hard
A. 201 Created, because the second update creates a new entity version
B. 204 No Content, because identical preconditions make requests idempotent
C. 304 Not Modified, because the request contains an outdated validator
D. 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?

Routing: Convention and Attribute Routing Hard
A. Route matching converts every query-string value into a path segment
B. Conventional routing ignores the path whenever a query string is present
C. Conventional routing supports query strings only for POST requests
D. Route matching generally uses the path and does not distinguish query-string keys

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?

Routing: Convention and Attribute Routing Hard
A. The {id:int} action, because a matching constrained parameter is more specific
B. The {status} action, because unconstrained strings accept all route values
C. Both actions, because Web API invokes every route that matches the path
D. Neither action, because overlapping attribute routes always produce an error

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?

Routing: Convention and Attribute Routing Hard
A. /api/customers/api/accounts/5
B. /accounts/api/customers/5
C. /api/customers/accounts/5
D. /api/accounts/5