Introduction to .NET Florin Olariu “Alexandru Ioan Cuza”, University of Iași Department of Computer Science
ASP.NET Web API - II
Agenda Status codes recap Demo : How to return child resources Demo : Working with serializer settings Content negotiation Demo: Content negotiation Demo : Creating a resource Demo : Validating input Demo : Updating a resource Demo : Deleting a resource Best practices in Web API’s Summary
Status codes recap
Status codes recap
Demo : How to return child resources
Demo : Working with serializer settings
Content negotiation
Content negotiation Formatters and Content negotiation What is the meaning?
Content negotiation Formatters and Content negotiation The idea is selecting the best representation for a given response when the are multiple representation available. In order to solve this goal we have to:
Content negotiation Formatters and Content negotiation The idea is selecting the best representation for a given response when the are multiple representation available. Pass media type via the accept header of the request Sample:
Content negotiation Formatters and Content negotiation The idea is selecting the best representation for a given response when the are multiple representation available. Pass media type via the accept header of the request application/json application/xml Formatters:
Content negotiation Deals with: output and input
Content negotiation
Demo: Content negotiation
Demo : Creating a resource
Demo : Validating input ModelState Data validation For custom validations make use of Fluent Validation https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Core/ https://www.exceptionnotfound.net/custom-validation-in-asp-net-web-api-with- fluentvalidation/
Demo : Updating a resource
Demo : Deleting a resource
One more thing…(1/2) Postel’s law.
Best practices for API’s One more thing…(2/2) Best practices for API’s https://medium.com/@schneidenbach/restful-api-best-practices-and- common-pitfalls-7a83ba3763b5#.6wmaehuhu
Summary Recap status codes Formatters and content negotiation Creating/updating/deleting updating resources Best practices
Bibliography Pluralsight
Questions Do you have any other questions?
Thanks! See you next time!