liveBook · Manning

Web service

As explained in ASP.NET Core in Action, 3e

An HTTP API application exposes application functionality through endpoints that communicate using the HTTP protocol.

A web service lets another application use functionality over HTTP. It exposes endpoints—URLs that clients can request to access or change server-side data. An HTTP API typically returns JSON rather than a finished HTML page: the client decides how to use or display the data. section 5.1

A browser-based single-page application might fetch JSON and build its own interface. A mobile app can use the same approach. Other backend services can also call endpoints; for example, an email service could accept an address and message from another application. “HTTP API” is the generic term here; “Web API” can also name a specific ASP.NET Core approach. section 5.1 section 3.2

Figure 5.2 A sample client-side SPA using Blazor WebAssembly. The initial requests load the SPA files into the browser, and subsequent requests fetch data from a web API, formatted as JSON.
CH05_F02_Lock3

The figure separates the initial download of a single-page application from its later requests for JSON data. Those later requests show where the API fits. section 5.1

In ASP.NET Core, minimal APIs are a simple way to build this kind of service. Web API applications offer another approach with more features and structure, with some cost to performance and convenience. Razor Pages and MVC instead commonly generate HTML on the server for direct viewing in a browser. section 3.2 section 1.2

To start a local ASP.NET Core API application:

  • Generate a project from a template. section 3.2
  • Restore dependencies, build the project, then run it. section 3.2

A service may also be a *client* of another web service. An e-commerce application, for instance, might call specialist services to send email or take payments. In C#, HttpClient makes outgoing requests, but creating and disposing of one for every request can cause socket exhaustion. Keeping one instance avoids that problem but can miss DNS changes, so client lifetime needs care. section 33.1

How ASP.NET Core in Action, 3e covers it

How deep it goes
Defines endpoints and JSON responses, compares ASP.NET Core API approaches, and identifies HttpClient lifecycle pitfalls; defers factory-based remedies.
Examples
Illustrates JSON requests from a single-page application, an email service used by other applications, and third-party services for e-commerce.
What it assumes
Assumes familiarity with C# or a similar object-oriented language; treats HTML and JavaScript familiarity as helpful rather than required.
What you can do after
Build it from scratch with an ASP.NET Core minimal API template, or call an external API while recognizing HttpClient lifecycle pitfalls.
How it connects
Connects HTTP, JSON, minimal APIs, Web APIs, single-page applications, mobile applications, and HttpClient.

Also explained in

Compare how 6 books explain web service →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.