Hands-On RESTful Web Services with ASP.NET Core 3
eBook - ePub

Hands-On RESTful Web Services with ASP.NET Core 3

Design production-ready, testable, and flexible RESTful APIs for web applications and microservices

Samuele Resca

Share book
  1. 510 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Hands-On RESTful Web Services with ASP.NET Core 3

Design production-ready, testable, and flexible RESTful APIs for web applications and microservices

Samuele Resca

Book details
Book preview
Table of contents
Citations

About This Book

Get up to speed with the latest features of C# 8, ASP.NET Core 3 and.NET Core 3.1 LTS to create robust and maintainable web services

Key Features

  • Apply design patterns and techniques to achieve a reactive, scalable web service
  • Document your web services using the OpenAPI standard and test them using Postman
  • Explore mechanisms to implement a secure web service using client-side SSL and token authentication

Book Description

In recent times, web services have evolved to play a prominent role in web development. Applications are now designed to be compatible with any device and platform, and web services help us keep their logic and UI separate. Given its simplicity and effectiveness in creating web services, the RESTful approach has gained popularity, and this book will help you build RESTful web services using ASP.NET Core.

This REST book begins by introducing you to the basics of the REST philosophy, where you'll study the different stages of designing and implementing enterprise-grade RESTful web services. You'll also gain a thorough understanding of ASP.NET Core's middleware approach and learn how to customize it. The book will later guide you through improving API resilience, securing your service, and applying different design patterns and techniques to achieve a scalable web service. In addition to this, you'll learn advanced techniques for caching, monitoring, and logging, along with implementing unit and integration testing strategies. In later chapters, you will deploy your REST web services on Azure and document APIs using Swagger and external tools such as Postman.

By the end of this book, you will have learned how to design RESTful web services confidently using ASP.NET Core with a focus on code testability and maintainability.

What you will learn

  • Gain a comprehensive working knowledge of ASP.NET Core
  • Integrate third-party tools and frameworks to build maintainable and efficient services
  • Implement patterns using dependency injection to reduce boilerplate code and improve flexibility
  • Use ASP.NET Core's out-of-the-box tools to test your applications
  • Use Docker to run your ASP.NET Core web service in an isolated and self-contained environment
  • Secure your information using HTTPS and token-based authentication
  • Integrate multiple web services using resiliency patterns and messaging techniques

Who this book is for

This book is for anyone who wants to learn how to build RESTful web services with the ASP.NET Core framework to improve the scalability and performance of their applications. Basic knowledge of C# and.NET Core will help you make the best use of the code samples included in the book.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Hands-On RESTful Web Services with ASP.NET Core 3 an online PDF/ePUB?
Yes, you can access Hands-On RESTful Web Services with ASP.NET Core 3 by Samuele Resca in PDF and/or ePUB format, as well as other popular books in Informatik & Programmierung in C#. We have over one million books available in our catalogue for you to explore.

Information

Year
2019
ISBN
9781789539240

Section 1: Getting Started

In this section, we will introduce you to all the macro concepts of REST APIs and ASP.NET Core. You will also learn about local development.
This section includes the following chapter:
  • Chapter 1, REST 101 and Getting Started with ASP.NET Core

REST 101 and Getting Started with ASP.NET Core

Nowadays, almost all applications rely on web services. A lot of them operate using the RESTful method. The resource-centric approach and the simplicity of the REST style have become an industry standard. Therefore, it is essential to understand the theory behind the REST way of working and why it is important. This chapter will introduce you to the Representational State Transfer (REST) method. We will see what the definition of REST is and how to identify REST-compliant web services. We will also introduce .NET Core 3.1 and ASP.NET Core, the brand new version of the open-source, cross-platform framework provided by Microsoft.
In summary, this chapter covers the following topics:
  • Overview of REST architectural elements
  • A brief introduction to the .NET ecosystem
  • Why you should choose .NET to build a RESTful web service
By the end of this chapter, you will have an overview of some useful tools and IDEs that you can use to start developing on .NET Core.
This chapter will cover some of the base concepts of .NET Core 3.1 and ASP.NET Core. You need to have either Windows, Linux, or macOS installed. The setup process will depend on which OS you are using. We'll look at the different tools that can be used to develop apps and web services in .NET Core.

REST

What is REST? Representational State Transfer (REST) is usually defined as a software architecture style that applies some constraints to a web service. It identifies a set of resource-centric rules that describe the roles and the interaction between the constraints of a distributed hypermedia system, instead of focusing on the implementation of the components. Although it is quite rare to find a REST service that does not use HTTP, the definition does not mention any of these topics and instead describes REST as media- and protocol-agnostic.
The preceding definition can be further explained with an example. Consider an e-commerce website. When you browse a list of products and click on one them, the browser interprets your click as a request to a specific resource; in this case, the details of the product you clicked on. The browser makes an HTTP call to the URI, which corresponds to the details of the product and asks for a specific resource using the URI. This process is shown in the following diagram:
The concept of REST is pretty similar: the client asks the server for a specific resource, and this allows them to navigate and obtain other information about resources stored on the server.

The importance of being REST compliant

Before we discuss REST, we should understand the importance of web services in the modern application development world.
A typical modern application uses web services to obtain and query data. Any company that develop any product or solution uses web services to deliver and track information. This is because it can be difficult to replicate all the data and every behavior you need for every client who uses your application. Web services are also useful for providing access to third-party clients and services. Consider, for example, the Application Programming Interfaces (APIs) of Google Maps or Instagram: these platforms expose information through HTTP to share it with other companies and services.
The REST approach to web service architecture became increasingly popular because it is straightforward and clear. Unlike some old methods, such as the Simple Object Access Protocol (SOAP) or the Windows Communication Foundation (WCF), REST services provide a clean way of querying data. Different information can be obtained using different URIs without the need for adding any overhead to requests.
Today, more than ever, our services need to be prepared to scale so that they can be adapted to consumers. In a world of different technologies and distributed teams around the globe, we should be able to transform our architecture to solve complex business challenges. HTTP and REST help us address these challenges.

REST requirements

Roy Thomas Fielding is the main person behind the formalization of the HTTP protocol and the REST style: he described them in his dissertation, Architectural Styles and the Design of Network-based Software Architectures (https://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm). Moreover, Fielding's dissertation clearly defines the constraints of a REST system, as follows:
  • Uniform interface
  • Stateless
  • Cacheable
  • Client-server
  • Layered system
  • Code on demand
All of these, apart from code on demand, are essential when we wish to define a web service as REST-compliant. To explain these concepts, we will use the APIs provided by The New York Times: https://developer.nytimes.com/. To use these APIs, you need to go through a pre-authentication process. You can get an API key for this from the following link: https://developer.nytimes.com/signup.

Uniform interface

Uniform interface refers to the separation between the client and the server. This is advantageous because it means that the two systems are independent. The first principle of a uniform interface is that it should be resource-based, which means that we should start to think in a resource-oriented way. Therefore, every object or entity inside our system is a resource and a URI uniquely identifies each of them. Furthermore, if we think about the HTTP protocol, each resource is presented to the client in the form of XML or JSON to decouple the client from the server.
Let's use The New York Times APIs to understand this topic. Consider the following URI:
http://api.nytimes.com/svc/archive/v1/2018/6.json?api-key={your_api_key}
It contains some precise information about the resources we are asking for, including the following:
  • The fact that we are getting information from the archive section of the newspaper data
  • The specific month we are asking for; in this case, June 2018
  • The fact that the resource will be serialized using JSON format

Manipulation of resources through representations

Let's take another API request provided by The New York Times:
https://api.nytimes.com/svc/books/v3/lists.json?api-key={your_api_key}&list=hardcover-fiction
This provides a list of books based on a category; in this case, this category is Hardcover Fiction. Let's analyze the response:
{
"status": "OK",
"copyright": "Copyright (c) 2018 The New York Tim...

Table of contents