Put Axum `Json` last in the handler
Axum extractors run from left to right in function-argument order. A body-consuming extractor such as Json<T can read the request body only once, so it must be the final argument. This example uses Axum 0.8.9.
Software Development
Explore practical guides and knowledge by category.
324 articles
Axum extractors run from left to right in function-argument order. A body-consuming extractor such as Json<T can read the request body only once, so it must be the final argument. This example uses Axum 0.8.9.
Authorization middleware decides on the server whether an already identified user may perform a particular action, and passes only permitted requests to the next handler. Using a document-editing API in Express 5, this article explains object-level permissions that role checks can miss, deny-by-default behavior, 401 and 403 responses, and middleware placement. Policy rules are injected by the service; the sample code has not been compiled or run.
Authentication middleware validates a request's credentials and, on success, makes verified user information available to later handlers. This article uses a Bearer-token API in Express 5 to explain the middleware boundary, placement, and error handling; token cryptography is delegated to a trusted authentication library. Authorization decisions about roles or resources and login-session management are separate concerns.
When an application cache stores authenticated responses, its key must reflect the access scope that can change the response. Two callers must not share a key when they can see different data, even if they request the same URL. A cache key does not replace authorization: check the caller's access before reading the cache.
At-least-once delivery retries messages to avoid losing them, while accepting that the same message may arrive more than once. A consumer processes a message and then acknowledges it; if a failure occurs before the acknowledgement, the broker may deliver it again. This does not mean a business effect happens exactly once: consumers must tolerate repeated work.
An AsyncAPI document is a machine-readable contract for a message-driven API: it describes the servers an application connects to, the channels it uses, the messages exchanged, and whether the documented application sends or receives them. This example documents a consumer receiving a signup event. It follows the current published AsyncAPI 3.1.0 specification; example host, topic, and fields are fictional.
When building an ASP.NET Core API, choose Minimal APIs or controllers first, then align service registrations and middleware order. Minimal APIs are a compact starting point for straightforward HTTP APIs; controllers can suit applications that rely on MVC features, complex organization, or established team conventions. Pipeline order and dependency-injection lifetimes affect behavior and tests.
ASGI (Asynchronous Server Gateway Interface) is the standard interface between asynchronous Python apps and protocol servers. The server provides a per-connection scope; the app receives events through receive and sends response events with send. An HTTP request has one scope per request, while a WebSocket scope lasts until the connection closes. This event model supports protocols that exchange multiple messages. This guide explains the ASGI 3 callable, HTTP/WebSocket events, and lifespan; it does not cover a framework API or server deployment.
API versioning is the policy for distinguishing and releasing changes so an API can evolve while keeping its contract with existing clients. Compatible changes, such as adding a response field, may fit within an existing version; changes that can break consumers, such as removing a field or changing its meaning, need a new version and a migration plan. There is no universally correct choice between path versioning (`/v2`) and header or query versioning, so choose based on consumers and operations, then plan how support will end.
Use the HTTP status to show the broad failure class and a stable machine-readable body with field-level information the client can correct. RFC 9457 Problem Details can provide a common outer format, with field errors as API-defined extensions; it is a standard option, not mandatory for every API.
The HTTP Sunset response header signals that the resource is expected to become unresponsive after a specific time. It is not meant merely to mark an API that is no longer recommended. Under RFC 8594, Sunset is a hint about expected unavailability; it does not guarantee which status code or behavior will occur on that date.
API sorting defines the order in which a collection is returned. OData uses $orderby, but REST APIs vary in the syntax they support. For paged lists or repeatable reads, state the sort explicitly and include a unique tie-breaker; do not let clients inject arbitrary database expressions.
An API schema is a machine-readable contract that describes the structure and constraints of data an API accepts or returns. For JSON APIs, JSON Schema can define an object's properties, types, required fields, and value limits; a validator checks whether a JSON instance follows those rules. Schema validation checks data shape. It does not guarantee authentication, business rules, or the server's overall behavior. This article uses JSON Schema Draft 2020-12 to define a product-creation request.
An API sandbox is an isolated environment for trying an integration without affecting real users or production transactions. Test accounts, credentials, and endpoints let you check requests, responses, and follow-up events. Do not assume a sandbox is identical to production: supported features, data, external connections, performance, and failure conditions can differ.
Pagination splits a large collection across multiple responses so a client can process a manageable portion and request the next page. API designers need to define ordering, behavior under concurrent changes, page size, and how clients continue; otherwise clients can miss or repeat records or request expensive pages.
API observability connects signals so you can explain where latency, errors, or traffic changes arise across a request path and its services—not merely whether a request succeeded. In OpenTelemetry, metrics reveal aggregate changes in service behavior, traces follow a request across services, and logs provide event detail. Correlating them with trace context and consistent route, status, and error attributes makes API incidents easier to narrow.
An API mock server is a test HTTP server that stands in for a real business service. It uses an OpenAPI description and examples to serve paths and responses, so client work can begin before the backend is ready and gaps in the contract can be found early. Mock responses do not prove persistence, authorization, transactions, or real service behavior.
An API key is a string credential that an API provider uses to identify requests or account for usage by a project or product. Some providers use a key to authenticate a caller, but many keys do not prove a user’s identity or permissions; they distinguish usage, quotas, or access configuration instead. Do not assume “whoever has the key is an authenticated user.” Check what security meaning that API assigns to its key type.
An API gateway is an entry layer between clients and backend services. It commonly routes requests received at one public address to the appropriate service and applies shared handling such as authentication, rate limiting, and observability. It can also combine responses from multiple services, but putting all composition logic in the gateway can create a bottleneck and widen the impact of failures. This article explains the pattern for microservices and HTTP APIs and how to decide whether to use it.
API filtering lets a client request only collection items that match conditions. A safe filter API defines which fields, operators, and value formats clients may use, then validates and applies them in the data store. It does not accept arbitrary SQL fragments or let client input set access permissions.