Skip to content
Download

Context

mach::Context

Represents the current HTTP request context.

Primary header:

#include <mach/Context.hpp>

Convenience header:

#include <mach/mach.hpp>
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;
};
Name Description
Context Creates a request context instance.
Name Description
request Represents the current HTTP request.
respnose Represents the current HTTP response.

Not thread-safe. Concurrent access to the same Context instance must be synchronized externally.

  • Owned by the framework.
  • Must not be copied, moved, or stored beyond the request handling lifetime.
  • 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.
app.mapGet("/users/{id:int}", [](mach::Context& context) {
auto id = context.request.routeParam<int>("id");
return mach::ok(id);
});
Name Description
Request Represents the current HTTP request.
Response Represents the HTTP response being built.
Results Creates HTTP responses from route handlers.