Web api

 Certainly! Here's a list of 100+ interview questions covering various aspects of .NET Web API:


**Basic Concepts:**


1. What is ASP.NET Web API, and why is it used?

2. Differentiate between ASP.NET Web API and WCF (Windows Communication Foundation).

3. Explain the architectural style that ASP.NET Web API follows.

4. What are the advantages of RESTful APIs, and how does Web API align with REST principles?

5. How does Web API differ from ASP.NET MVC?


**HTTP and REST Concepts:**


6. Describe the HTTP methods commonly used in Web API.

7. What is the purpose of HTTP status codes in Web API responses?

8. Explain the difference between PUT and POST HTTP methods.

9. Describe the role of HTTP headers in Web API requests and responses.

10. How do you handle versioning in Web API?

11. What is content negotiation, and why is it important in Web API?


**Routing and Attribute Routing:**


12. What is routing, and how does it work in Web API?

13. Explain attribute routing in Web API.

14. How do you define route constraints in Web API?

15. What is the role of route parameters in Web API routing?

16. Describe the order in which routes are matched in Web API.


**Controllers and Actions:**


17. What is a Web API controller, and how do you create one?

18. Explain the role of actions in Web API controllers.

19. How are action methods mapped to HTTP methods in Web API?

20. How can you restrict access to certain actions based on user roles?

21. What is the purpose of the [Route] attribute on action methods?

22. How do you handle multiple HTTP methods for a single action?


**Model Binding and Validation:**


23. What is model binding, and how does it work in Web API?

24. Explain how model binding works for different data formats (JSON, XML, Form Data).

25. How do you customize model binding in Web API?

26. Describe the role of data annotations for model validation in Web API.

27. What is the ModelState, and how is it used for validation?

28. How can you perform client-side validation in Web API?


**Content Negotiation:**


29. What is content negotiation, and how does Web API use it?

30. How do you return data in different formats (XML, JSON) based on client preferences?

31. Explain how to specify content types in Web API requests and responses.

32. How can you support custom media types in content negotiation?


**Dependency Injection and IoC:**


33. What is dependency injection (DI), and why is it important in Web API?

34. Explain how to use dependency injection in Web API controllers.

35. How do you register and resolve dependencies in Web API?

36. Describe the differences between transient, scoped, and singleton dependencies in DI.


**Authentication and Authorization:**


37. How do you implement authentication in a Web API?

38. Explain token-based authentication and its use in Web API.

39. Describe the use of JWT (JSON Web Tokens) for authentication in Web API.

40. What is the purpose of authorization in Web API?

41. How do you implement role-based authorization in Web API?

42. How can you protect certain actions with the [Authorize] attribute?


**Exception Handling:**


43. How do you handle exceptions in Web API controllers?

44. Explain the use of exception filters in Web API.

45. What is the difference between global exception handling and action-level exception handling in Web API?

46. How can you return custom error responses in Web API?


**Action Filters:**


47. What are action filters in Web API, and why are they used?

48. Describe the execution order of action filters in Web API.

49. How do you create custom action filters in Web API?

50. What is the purpose of the [AllowAnonymous] attribute in Web API?


**Model Validation:**


51. How do you perform model validation in Web API?

52. Explain how to use data annotations for validation in Web API models.

53. How can you implement custom validation logic for model properties?

54. Describe the use of the [Required] attribute for model properties.


**Routing and Versioning:**


55. How can you version Web API endpoints?

56. Explain URI-based versioning and its advantages.

57. What is the purpose of the [RoutePrefix] attribute in versioning?

58. How do you handle versioning through HTTP headers in Web API?

59. Describe the challenges of versioning and how to mitigate them.


**Parameter Binding:**


60. How does parameter binding work in Web API?

61. Explain the difference between FromUri and FromBody parameter binding.

62. How do you handle optional parameters in Web API actions?

63. What is the role of the [FromBody] attribute, and when should it be used?


**Query Parameters and Filtering:**


64. How can you handle query parameters in Web API actions?

65. Explain how to filter and sort data in Web API using query parameters.

66. What is OData, and how can you implement it in Web API for querying?


**Media Formatters:**


67. What are media formatters in Web API, and why are they important?

68. Describe the role of media formatters in content negotiation.

69. How do you create a custom media formatter in Web API?

70. Explain how to support custom media types using media formatters.


**Error Handling and Logging:**


71. How do you log errors and exceptions in Web API?

72. Explain the use of logging frameworks like Serilog or NLog in Web API.

73. Describe the purpose of request and response logging in Web API.

74. How can you handle and log unhandled exceptions globally in Web API?


**Testing in Web API:**


75. How do you write unit tests for Web API controllers?

76. Explain how to use mocking frameworks like Moq for testing in Web API.

77. How do you write integration tests for Web API controllers?

78. What is the purpose of the `HttpServer` class for testing Web API?


**Content Negotiation and Serialization:**


79. How do you customize JSON serialization in Web API?

80. Explain how to handle circular references and reference loops during JSON serialization.

81. Describe how to customize XML serialization in Web API.

82. What is the use of the [DataContract] and [DataMember] attributes in Web API serialization?


**Cross-Origin Resource Sharing (CORS):**


83. What is CORS, and why is it important in Web API?


Comments

Popular posts from this blog

Swagger fiddler postman

Architecture in SDLC

. Net framework