- Mastering ASP.NET Web API
- Mithun Pattankar Malendra Hurbuns
- 543字
- 2021-07-02 20:52:29
Introducing web API
Any method(s) that is accessible over the web using HTTP verbs is called a web API. It is a lightweight way of transmitting data over HTTP, easily consumed by various clients like browsers, desktop apps, handheld devices, or even other SOA applications.
For a web API to be a successful HTTP-based service, it needed a strong web infrastructure like hosting, caching, concurrency, logging, security, and so on. One of the best web infrastructures was none other than ASP.NET.
ASP.NET, either in the form of a Web Form or an MVC, was widely adopted, so the solid base for web infrastructure was mature enough to be extended as a Web API.
Microsoft responded to the community needs by creating ASP.NET Web API--a super-simple yet very powerful framework for building HTTP-only, JSON-by-default web services without all the fuss of WCF.
The ASP.NET Web API can be used to build REST-based services in a matter of minutes, and can be easily consumed with any of the frontend technologies.
It was launched in 2012 with the most basic needs for HTTP-based services like convention-based Routing, HTTP Request, and Response messages.
Later, Microsoft released the much bigger and better ASP.NET Web API 2 along with ASP.NET MVC 5 in Visual Studio 2013.
ASP.NET Web API 2 evolved at a much faster pace with these features:
- Installing of the web API 2 was made simpler by using NuGet; you can create either an empty ASP.NET or MVC project, and then run the following command on the NuGet Package Manager Console:
Install-Package Microsoft.AspNet.WebApi
- The initial release of the web API was based on convention-based routing, which means that we define one or more route templates, and work around it. It's simple without much fuss, as the routing logic is in a single place, and it's applied across all controllers.
- The real-world applications are more complicated with resources (controllers/ actions) having child resources, for example, customers having orders, books having authors, and so on. In such cases, convention-based routing is not scalable.
- Web API 2 introduced a new concept of Attribute Routing, which uses attributes in programming languages to define routes. One straightforward advantage is that the developer has full control over how URIs for the web API are formed.
- Here a is quick snippet of Attribute Routing:
Route("customers/{customerId}/orders")] public IEnumerable<Order>GetOrdersByCustomer(int customerId) { ... }
- An ASP.NET Web API lives on the ASP.NET framework, which may lead you to think that it can be hosted on IIS only. However, using OWIN self-host, it can be hosted without IIS also.
- If any web API is developed using either the .NET or non-.NET technologies, and is meant to be used across different web frameworks, then enabling CORS is a must.
- IHTTPActionResult and web API OData improvements are other few notable features which helped web API 2 evolve as a strong technology for developing HTTP-based services.
- ASP.NET Web API 2 has become more powerful over the years with C# language improvements like asynchronous programming using Async/Await, LINQ, Entity Framework Integration, Dependency Injection with DI frameworks, and so on.
- Bootstrap Site Blueprints Volume II
- Getting Started with React
- ASP.NET Core 5.0開發入門與實戰
- Unity 2020 Mobile Game Development
- Java編程指南:基礎知識、類庫應用及案例設計
- Learning ELK Stack
- Kotlin開發教程(全2冊)
- TMS320LF240x芯片原理、設計及應用
- JQuery風暴:完美用戶體驗
- Mastering Leap Motion
- JavaScript前端開發基礎教程
- 高質量程序設計指南:C++/C語言
- Koa與Node.js開發實戰
- Pandas入門與實戰應用:基于Python的數據分析與處理
- Java EE企業級應用開發教程:Spring+Spring MVC+MyBatis(第2版)