Mastering ASP.NET Web API
Mithun Pattankar, Malendra Hurbuns
- 330 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Mastering ASP.NET Web API
Mithun Pattankar, Malendra Hurbuns
About This Book
Leverage ASP.Net Web API to build professional web services and create powerful applications.About This Book⢠Get a comprehensive analysis of the latest specification of ASP.NET Core and all the changes to the underlying platform that you need to know to make the most of the web API⢠See an advanced coverage of ASP.NET Core Web API to create robust models for your data, create controllers, and handle routing and security⢠This book is packed with key theoretical and practical concepts that can be instantly applied to build professional applications using API with Angular 4, Ionic, and React Who This Book Is ForThis book is for.Net developers who wants to Master ASP.NET Core (Web API) and have played around with previous ASP.NET Web API a little, but don't have in-depth knowledge of it. You need to know Visual Studio and C#, and have some HTML, CSS, and JavaScript knowledge.What You Will Learn⢠Acquire conceptual and hands-on knowledge of ASP.NET Core (MVC & Web API)⢠Learn about HTTP methods, the structure of HTTP content, internet media types, and how servers respond to HTTP requests and their associated HTTP codes⢠Explore middleware, filters, routing, and unit testing⢠Optimize Web API implementations⢠Develop a secure Web API interface⢠Deploy Web API projects to various platforms⢠Consume your web API in front end application based on Angular 4, Bootstrap, and Ionic⢠Implement and explore the current trends in service architectureIn DetailMicrosoft has unified their main web development platforms. This unification will help develop web applications using various pieces of the ASP.NET platform that can be deployed on both Windows and LINUX. With ASP.NET Core (Web API), it will become easier than ever to build secure HTTP services that can be used from any client.Mastering ASP.NET Web API starts with the building blocks of the ASP.NET Core, then gradually moves on to implementing various HTTP routing strategies in the Web API. We then focus on the key components of building applications that employ the Web API, such as Kestrel, Middleware, Filters, Logging, Security, and Entity Framework.Readers will be introduced to take the TDD approach to write test cases along with the new Visual Studio 2017 live unit testing feature. They will also be introduced to integrate with the database using ORMs. Finally, we explore how the Web API can be consumed in a browser as well as by mobile applications by utilizing Angular 4, Ionic and ReactJS.By the end of this book, you will be able to apply best practices to develop complex Web API, consume them in frontend applications and deploy these applications to a modern hosting infrastructure.Style and approachUsing a hands-on approach, we cover both the conceptual as well as the technical aspects of the ASP.NET Core (Web API) framework.
Frequently asked questions
Information
Anatomy of ASP.NET Core Web API
- A quick recap of the MVC framework
- Inception of web APIs and their evolution
- Introduction to .NET Core
- An overview of the ASP.NET Core Architecture
- Creating an ASP.NET Core Project using Visual Studio IDE
- Creating an ASP.NET Core Project in Linux/macOS
- Examining the ASP.NET Core project files and structures
- Understanding Request processing
- MVC and web API unification
- Running the ASP.NET Core Web API
A quick recap of the MVC framework
- Models (M): These are classes that represent the domain model. Most of them represent the data stored in a database, for example, Employee, Customer, and so on.
- View (V): This is a dynamically generated HTML page as template.
- Controller (C): This is a class that manages the interaction between the View and the Model. Any operation on a View should have a corresponding handling in the Controller like user inputs, render appropriate UI, Authentication, Logging, and so on.
Inception of Web APIs and their evolution
- With applications in production, the amount of data used while communicating started to explode, and transferring them over the network was bandwidth consuming.
- SOAP, being lightweight to some extent, started to show signs of payload increase. A few KB SOAP packets would become a few MB of data transfer.
- Consuming the SOAP service in applications led to huge application sizes because of WSDL and proxy generation. This was even worse when it was used in web applications.
- Any changes to the SOAP services led to updating the service proxy to reflect changes. This wasn't an easy task for any developer.
- JavaScript-based web frameworks were released, and gained ground for a much simpler way of web development. Consuming SOAP-based services was not that optimal.
- Hand-held devices, like tablets and smartphones, became popular. They had more focused applications, and needed a very lightweight service-oriented approach.
- Browser-based Single Page Applications (SPA) gained ground very rapidly. Using SOAP-based services was quite heavy for these SPA.
- Microsoft released REST-based WCF components, which can be configured to respond in JSON or XML, but still it was built on top of heavy technology of WCF.
- Applications where no longer just large enterprise services, and there was a need for a more focused, lightweight, and easy-to-use service, which could be up and running in a few days.
Introducing web API
- 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 we...