RESTful services may or may not be a part of a web application. A web application may call or consume external APIs or services from the same application. The program that enables the interaction or communication (request, response) between the services and the application consuming those services is called a client.
A client helps applications to communicate (Request, Response) with APIs.
In this section, we will create a web client. A web client is an application or program written in ASP.NET Core.
Before we build a test web client, we need to discuss what we have to call.
Continuing our example of the FlixOne BookStore, the following table lists the produces and services that we will call and consume:
API resource |
Description |
GET /api/product |
Gets a list of products. |
GET /api/product{id} |
Gets a product. |
PUT /api/product{id} |
Updates an existing product. |
DELETE /api/product{id} |
Deletes an existing product. |
POST /api/product |
Adds a new product. |
Our FlixOne product service is designed for the following tasks:
- Adding a new product
- Updating an existing product
- Deleting an existing product
- Retrieving a product
We have already ensured Swagger support for our product APIs (please refer to the previous chapters for more information), so let's get going. To start with this project, follow these steps:
- First, run Visual Studio 2017
- Select File | Open
- Select the project FlixOne.BookStore.ProductService
- Run the project by pressing F5 or clicking directly from the menu
- Enter the following URL: http://localhost:10065/swagger/
You should now see Swagger documentation for your Product APIs, as shown in the following screenshot: