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

Interface for HTTP request handlers. More...

#include <httpd.hpp>

Inheritance diagram for NNet::IRouter:
NNet::THelloWorldRouter

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.SendHeaders();
co_await res.WriteBodyFull("hello");
}
};
Represents an incoming HTTP/1.1 request.
Definition httpd.hpp:53
Builds and sends an HTTP/1.1 response.
Definition httpd.hpp:126
void SetStatus(int statusCode)
Sets the HTTP status code (default is 200). Must be called before SendHeaders.
Definition httpd.cpp:283
TFuture< void > WriteBodyFull(const std::string &data)
Sends headers (with Content-Length) and the full body in one call.
Definition httpd.cpp:356
TFuture< void > SendHeaders()
Sends the status line and all accumulated headers to the client.
Definition httpd.cpp:305
void SetHeader(const std::string &name, const std::string &value)
Adds or replaces a response header. Must be called before SendHeaders.
Definition httpd.cpp:287
Interface for HTTP request handlers.
Definition httpd.hpp:194
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: