Mastering ASP.NET Web API
eBook - ePub

Mastering ASP.NET Web API

Mithun Pattankar, Malendra Hurbuns

Buch teilen
  1. 330 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Mastering ASP.NET Web API

Mithun Pattankar, Malendra Hurbuns

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

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.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Mastering ASP.NET Web API als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Mastering ASP.NET Web API von Mithun Pattankar, Malendra Hurbuns im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Informatica & Linguaggi di programmazione. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2017
ISBN
9781786469380

Anatomy of ASP.NET Core Web API

This chapter starts with a quick recap of MVC. You might be surprised why we need MVC when we are working with web APIs. It's because the ASP.NET Web API is designed based on the MVC principles of Controllers, Models, and Views (the response returned can be treated as a faceless view in the case of a Web API).
Our focus in this chapter is to know why we need a lightweight HTTP-based service technology in the form of a Web API, its evolution to meet the constantly changing industry demands, the entry of Microsoft into the world of Open Source in the form of .NET Core and ASP.NET Core apps, and not limiting ourselves to the world of Windows OS for developing ASP.NET web applications.
In this chapter, we will be looking at the following topics:
  • 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

A Model-View-Controller (MVC) is a powerful and elegant way of separating concerns within an application, and applies itself extremely well to web applications.
With ASP.NET MVC, MVC stands for the following:
  • 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

Looking back to the days when the ASP.NET ASMX-based XML web service was widely used for building service-oriented applications, it was the easiest way to create a SOAP (Simple Object Access Protocol)-based service that could be used by both .NET applications and non-.NET applications. It was available only over HTTP.
In the late 2007, Microsoft released Windows Communication Foundation (WCF). WCF was and is, even now, a powerful technology for building SOA-based applications. It was a giant leap in the world of the Microsoft .NET world.
WCF was flexible enough to be configured as an HTTP service, remoting service, TCP service, and so on. Using the contracts of WCF, we would keep the entire business logic code base the same, and expose the service as HTTP-based or non-HTTP-based via SOAP/non SOAP.
Until 2010, the ASMX-based XML web service, or WCF service, was widely used in client-server-based applications; in fact, everything was running smoothly.
But the developers of the .NET and non-.NET community started to feel the need for a completely new SOA technology for client-server applications. Some of the reasons behind this were as follows:
  • 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.
Any developer who has seen the evolving nature of SOA-based technologies such as ASMX, WCF, or any SOAP-based technology, felt the need to have much lighter, HTTP-based services.
HTTP-only, JSON-compatible POCO (Plain Old CLR Object)-based lightweight services was the need of the hour, and the concept of Web APIs started gaining momentum.

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) { ... } 
For more details on this, read Attribute Routing in ASP.NET Web API 2 at https://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2.
  • 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...

Inhaltsverzeichnis