- 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.
- Django Design Patterns and Best Practices
- FFmpeg入門詳解:音視頻原理及應(yīng)用
- Mastering JavaScript Design Patterns(Second Edition)
- 微服務(wù)從小白到專家:Spring Cloud和Kubernetes實(shí)戰(zhàn)
- App Inventor創(chuàng)意趣味編程進(jìn)階
- 代替VBA!用Python輕松實(shí)現(xiàn)Excel編程
- FFmpeg開發(fā)實(shí)戰(zhàn):從零基礎(chǔ)到短視頻上線
- 玩轉(zhuǎn).NET Micro Framework移植:基于STM32F10x處理器
- Instant Automapper
- Web前端測試與集成:Jasmine/Selenium/Protractor/Jenkins的最佳實(shí)踐
- Unity 5 Game Optimization
- Java編程指南:語法基礎(chǔ)、面向?qū)ο蟆⒑瘮?shù)式編程與項(xiàng)目實(shí)戰(zhàn)
- JBoss AS 7 Development
- C#程序開發(fā)參考手冊
- Python深度學(xué)習(xí):基于PyTorch