HTTP response builder (fluent interface)
| 93 | |
| 94 | /// HTTP response builder (fluent interface) |
| 95 | class Response { |
| 96 | public: |
| 97 | Response() FL_NOEXCEPT; |
| 98 | |
| 99 | /// Set HTTP status code |
| 100 | /// @param code Status code (e.g., 200, 404, 500) |
| 101 | /// @return Reference to this for chaining |
| 102 | Response& status(int code); |
| 103 | |
| 104 | /// Add HTTP header |
| 105 | /// @param name Header name |
| 106 | /// @param value Header value |
| 107 | /// @return Reference to this for chaining |
| 108 | Response& header(const string& name, const string& value); |
| 109 | |
| 110 | /// Set response body |
| 111 | /// @param content Body content |
| 112 | /// @return Reference to this for chaining |
| 113 | Response& body(const string& content); |
| 114 | |
| 115 | /// Set JSON response body with automatic Content-Type header |
| 116 | /// @param data JSON object to serialize |
| 117 | /// @return Reference to this for chaining |
| 118 | Response& json(const class json& data); |
| 119 | |
| 120 | /// Factory method for 200 OK response |
| 121 | /// @param body Optional body content |
| 122 | /// @return Response with status 200 |
| 123 | static Response ok(const string& body = ""); |
| 124 | |
| 125 | /// Factory method for 404 Not Found response |
| 126 | /// @return Response with status 404 |
| 127 | static Response not_found(); |
| 128 | |
| 129 | /// Factory method for 400 Bad Request response |
| 130 | /// @param message Error message |
| 131 | /// @return Response with status 400 |
| 132 | static Response bad_request(const string& message); |
| 133 | |
| 134 | /// Factory method for 500 Internal Server Error response |
| 135 | /// @param message Error message |
| 136 | /// @return Response with status 500 |
| 137 | static Response internal_error(const string& message); |
| 138 | |
| 139 | private: |
| 140 | friend class Server; |
| 141 | |
| 142 | int mStatusCode = 200; |
| 143 | string mBody; |
| 144 | map<string, string> mHeaders; |
| 145 | |
| 146 | string to_string() const; |
| 147 | }; |
| 148 | |
| 149 | /// Route handler function signature |
| 150 | /// Takes const reference to Request, returns Response by value |
no outgoing calls
no test coverage detected