liveBook · Manning

Client-server architecture

As explained in Building Web APIs with ASP.NET Core

The client-server approach separates client user-interface concerns from server-side data and application concerns.

Client-server architecture separates the user interface from data storage and application concerns. A browser or other client sends requests; the web API responds without needing to know how that client was built. This separation lets each side change independently and helps keep the system simpler to maintain. section 1.1.4 section 3.1.1

For a web API, the boundary is practical: controllers and Minimal APIs return standard HTTP responses rather than client-specific output. The API responds to client-initiated requests; it does not initiate requests to clients. section 3.1.1

A separate client still needs permission to call the API from a browser. The same-origin policy restricts scripts from requesting a different protocol, host, or port. Cross-Origin Resource Sharing (CORS) uses HTTP headers to permit selected cross-origin requests. It controls browser access; it does not change the separation between client and server. section 3.1.1

builder.Services.AddCors(options => {
   options.AddDefaultPolicy(cfg => {
       cfg.WithOrigins(builder.Configuration["AllowedOrigins"]);
       cfg.AllowAnyHeader();
       cfg.AllowAnyMethod();
   });
   options.AddPolicy(name: "AnyOrigin",
       cfg => {
           cfg.AllowAnyOrigin();
           cfg.AllowAnyHeader();
           cfg.AllowAnyMethod();
       });
   });

This ASP.NET Core configuration registers a default CORS policy using AllowedOrigins and a named AnyOrigin policy. Both permit any header and method, but the named policy permits any origin; choose the policy appropriate to the clients that need access. section 3.1.1

After registering a policy, add CORS middleware with app.UseCors() or apply a named policy to selected endpoints with RequireCors("AnyOrigin"). This makes cross-origin access an explicit API configuration decision. section 3.1.1

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Defines the separation and applies it to HTTP responses and CORS configuration, without detailing client or server internals.
Examples
Uses controllers, Minimal APIs, and ASP.NET Core CORS policies to show how independent clients reach an API.
What it assumes
Introduces the client-server constraint and CORS, while assuming a web API project with controllers or Minimal APIs.
What you can do after
Operate/configure client access to an ASP.NET Core API with CORS middleware or endpoint policies while keeping responses client-independent.
How it connects
Connects REST, separation of concerns, HTTP, same-origin policy, and Cross-Origin Resource Sharing.

Also explained in

Compare how 5 books explain client-server architecture →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.