Context
mach::Context
Description
Section titled “Description”Represents the current HTTP request context.
Headers
Section titled “Headers”Primary header:
#include <mach/Context.hpp>Convenience header:
#include <mach/mach.hpp>Syntax
Section titled “Syntax”struct Context {
Context(Request&& request, Response&& response);
Context(const Context&) = delete; Context& operator=(const Context&) = delete;
Context(Context&&) = delete; Context& operator=(Context&&) = delete;
Request request; Response response;};Constructors
Section titled “Constructors”| Name | Description |
|---|---|
Context |
Creates a request context instance. |
Data Members
Section titled “Data Members”| Name | Description |
|---|---|
request |
Represents the current HTTP request. |
respnose |
Represents the current HTTP response. |
Thread Safety
Section titled “Thread Safety”Not thread-safe. Concurrent access to the same Context instance must be synchronized externally.
Ownership
Section titled “Ownership”- Owned by the framework.
- Must not be copied, moved, or stored beyond the request handling lifetime.
Remarks
Section titled “Remarks”- A new context is created for each HTTP request.
- The same context instance is shared by all middleware and the selected route handler for the request.
- Modifications to the response are reflected in the HTTP response sent to the client.
Example
Section titled “Example”app.mapGet("/users/{id:int}", [](mach::Context& context) { auto id = context.request.routeParam<int>("id");
return mach::ok(id);});See Also
Section titled “See Also”| Name | Description |
|---|---|
Request |
Represents the current HTTP request. |
Response |
Represents the HTTP response being built. |
Results |
Creates HTTP responses from route handlers. |