Applying web API concepts and best practices

ASP.NET Core 3 combines the best features of ASP.NET MVC and web APIs into a single framework. This makes complete sense since they provide many similar functionalities.

Before this merger, developers had to rewrite code when they needed to expose data in different formats via MVC and web APIs. They had to work with multiple frameworks and concepts at the same time. Fortunately, this entire process has been completely streamlined in ASP.NET Core 3, as you will see in this chapter.

The following diagram illustrates how client HTTP requests are handled by ASP.NET Core 3 in terms of web APIs and MVC:

 

Web APIs normally use either JSON or XML as a response format. JSON is the preferred format since it has become a quasi-standard on the market and most modern applications use it due to its simplicity and efficiency.

Furthermore, filters and middleware can be used with web APIs since ASP.NET Core 3 manages web APIs the same way it does for standard MVC Controllers. This can be quite handy in some use cases and developers can apply their skills more widely.

In general, there are three different styles for creating web APIs when using ASP.NET Core 3:

  • RPC-style
  • REST-style
  • HATEOAS-style

Note that it is also possible to use the Simple Object Access Protocol (SOAP) to create web APIs, but it is not recommended. Instead, SOAP should be used in the context of standard web services, which is why it is not shown in the following examples.

We will present each style in more detail, along with some practical examples, which will help you decide on your own integration strategy.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.15.84