COROIO: NNet::IRouter Struct Reference
COROIO
Loading...
Searching...
No Matches
NNet::IRouter Struct Referenceabstract

Interface for HTTP request handlers. More...

#include <httpd.hpp>

Public Member Functions

virtual TFuture< void > HandleRequest (TRequest &request, TResponse &response)=0

Detailed Description

Interface for HTTP request handlers.

Implement HandleRequest to process requests and write responses. A single router instance is shared across all connections; implementations must be stateless or protect shared state explicitly (though a single-threaded event loop means no concurrent calls in practice).

struct MyRouter : IRouter {
TFuture<void> HandleRequest(TRequest& req, TResponse& res) override {
res.SetStatus(200);
res.SetHeader("Content-Type", "text/plain");
co_await res.WriteBodyFull("hello");
}
};
Represents an incoming HTTP/1.1 request.
Definition httpd.hpp:56
Builds and sends an HTTP/1.1 response.
Definition httpd.hpp:131
void SetStatus(int statusCode)
Sets the HTTP status code (default is 200). Must be called before SendHeaders.
Definition httpd.cpp:294
TFuture< void > WriteBodyFull(const std::string &data)
Writes the full body, sending the headers first if they were not sent yet.
Definition httpd.cpp:368
void SetHeader(const std::string &name, const std::string &value)
Adds or replaces a response header. Must be called before SendHeaders.
Definition httpd.cpp:298
Interface for HTTP request handlers.
Definition httpd.hpp:200
Owned coroutine handle that carries a result of type T.
Definition corochain.hpp:185

The documentation for this struct was generated from the following file: