liveBook · Manning

Stateless system

As explained in Building Web APIs with ASP.NET Core

Statelessness is an interaction constraint in which the server retains no client context between requests.

A stateless web API handles each request without retaining client context from earlier calls. The client supplies the context needed for that call, such as authentication information. Statelessness is a REST constraint that reduces server-side request overhead and can improve scalability under heavy load. section 1.1.4

For a stateless board-game API:

  • Keep session-related information on the client rather than storing it on the server for later requests. section 3.1.2
  • Do not rely on ASP.NET Core session state, server-side client context, or load-balancer features such as session affinity and sticky sessions. section 3.1.2
  • Keep the distinction clear: storing board-game resources or returning resource state is allowed. The restriction concerns retained information about a client’s previous interactions. section 3.1.2

A starting point for the board-game API

A minimal ASP.NET Core web API without authentication is already stateless when it has no session-state services or middleware enabled. If adding, updating, or deleting games later requires authorization, the client will need to supply the required information with its calls rather than depend on a server-side session. Token-based authentication with JSON Web Tokens is a later approach, not a feature of this starting API. section 3.1.2

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Defines the constraint and identifies prohibited session mechanisms, while deferring token-based authentication implementation.
Examples
Uses a minimal ASP.NET Core board-game API without authentication to show an already-compliant starting point.
What it assumes
Defines statelessness in plain terms while applying it to an existing minimal ASP.NET Core web API.
What you can do after
Operate/configure it by avoiding server-side client sessions and requiring clients to provide needed context with each call.
How it connects
Connects statelessness to REST, session state, client-side state management, load balancing, and token-based authentication.

Also explained in

Compare how 14 books explain stateless system →

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.