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. Remote Execution Service Tool
B. Responsive Server Transfer
C. Representational State Transfer
D. Resource Exchange Standard Type

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

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

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

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

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. PSD
C. EXE
D. MP3

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. ViewController
C. ApiController
D. FormController

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

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

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

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

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

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

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

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

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

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

12 What does a database connection string contain?

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

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. HTML
C. Bootstrap
D. Entity Framework

14 What does the letter C represent in CRUD?

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

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

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

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

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

17 Which HTTP method is used to remove a resource?

ASP.NET Web API CRUD Operations Easy
A. DELETE
B. PUT
C. GET
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. Designing web page layouts
C. Sending and testing HTTP requests
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. Response body
B. Request URL
C. Method list
D. Workspace name

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

Routing: Convention and Attribute Routing Easy
A. view/{page}/{name}
B. api/{controller}/{id}
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. Statelessness
C. Uniform interface
D. Cacheability

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. CONNECT
C. POST
D. PUT

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 client's Accept header
B. From the database column types
C. From the controller's file extension
D. From the action method's name

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. DbSet<Product>
B. JsonMediaTypeFormatter
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. Remove the fields from the database
C. Store the hidden fields as null
D. Create and return a dedicated DTO

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 async Task<IHttpActionResult> GetProducts()
B. public DbSet<Product> GetProducts()
C. public Product GetProducts()
D. public void 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. ProductController
B. ProductsController
C. ProductServiceController
D. ProductsApiController

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 DataTable Products { get; set; }
D. public List<Product> 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. Restart IIS and rebuild the controller
B. Add a new route for the property
C. Rename the connection string and retry
D. Create a migration and update the database

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. 201 Created with no body
C. 404 Not Found
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. Update both product 8 and product 11
B. Reject the request as inconsistent
C. Create a new product with ID 8
D. Ignore the URI and update product 11

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. 204 No Content
B. 405 Method Not Allowed
C. 201 Created
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. Content-Type: application/json
B. Authorization: application/json
C. Accept-Encoding: application/json
D. Cache-Control: 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. Location: application/xml
B. Content-Length: application/xml
C. Accept: application/xml
D. Host: 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/7/products
B. /api/products/7
C. /products/api/7
D. /api/products?id/name/7

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/25
C. GET /api/products/twenty
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.MapHttpAttributeRoutes();
B. config.EnsureInitialized();
C. config.Routes.Clear();
D. config.Formatters.Clear();

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

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. 304 Not Modified, because the cached representation is stale
D. 409 Conflict, because every concurrent update uses that status

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 URI, while update is read from the body
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 body, while update is read from the URI

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. JSON, because ASP.NET Web API always prioritizes its JSON formatter
B. XML, because XML is selected whenever multiple formatters are available
C. JSON, because the two media types represent equivalent resources
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 → Controller → Compression; response: Compression → Controller → Audit
B. Request: Compression → Audit → Controller; response: Controller → Audit → Compression
C. Request: Audit → Compression → Controller; response: Controller → Compression → Audit
D. Request: Controller → Audit → Compression; response: Compression → Audit → Controller

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 MapHttpAttributeRoutes() only inside each API controller
C. Call MapHttpRoute(...) before calling MapHttpAttributeRoutes()
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. public abstract class InventoryController : ApiController
B. public class InventoryController : ApiController
C. public class InventoryService : ApiController
D. internal class InventoryController : 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. Serialize the submitted entity to XML before attaching it to the context
B. Accept a dedicated update DTO and copy only permitted fields to the loaded entity
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. Convert the order query to AsEnumerable() before accessing customers
B. Project orders and customer names into a DTO within the LINQ query
C. Call SaveChanges() before enumerating the collection of orders
D. Create a separate DbContext for each order returned by the endpoint

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. 500 Internal Server Error, because concurrency is a database exception
B. 404 Not Found, because the requested version no longer exists
C. 412 Precondition Failed, because the update condition became false
D. 400 Bad Request, because the submitted entity failed model validation

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. CreatedAtRoute("GetProduct", new { id = product.Id }, product)
B. StatusCode(HttpStatusCode.NoContent)
C. Ok(product)
D. RedirectToRoute("GetProduct", new { id = product.Id })

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. Create both products because PUT is required to duplicate representations
D. Return 400 Bad Request because the URI and representation identify different resources

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. Yes, because an idempotent method cannot return 404 Not Found
B. No, because the resource state after either request remains deleted
C. Yes, because every repeated request must return the same status code
D. No, because DELETE is defined as a safe method without side effects

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. Set Content-Type: application/json for the request body
D. Add Cache-Control: no-cache to disable cached media types

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-Match: "7"
B. If-None-Match: 7
C. If-Unmodified-Since: 7
D. Last-Modified: "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. 204 No Content, because identical preconditions make requests idempotent
B. 201 Created, because the second update creates a new entity version
C. 412 Precondition Failed, because the original ETag is now stale
D. 304 Not Modified, because the request contains an outdated validator

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. Route matching generally uses the path and does not distinguish query-string keys
D. Conventional routing supports query strings only for 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?

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

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. /accounts/api/customers/5
B. /api/customers/api/accounts/5
C. /api/accounts/5
D. /api/customers/accounts/5