Status codes
An HTTP status code is a three-digit integer on the response that classifies the outcome: 2xx success, 3xx redirect, 4xx client error, 5xx server error. C++ clients read it from the library (res->status, CURLINFO_RESPONSE_CODE). Servers set it on the response object.
Detailed Explanation
The status is the first thing a client should branch on. 200 with an error object in the body is a lie that breaks generic clients. 404 means the resource is missing. 400 means the request is unusable. 401 means authenticate. 403 means authenticated but not allowed. 409 means conflict (idempotency key reused with a different body). 429 means slow down. 500 means the server failed. 502/503/504 are gateway and overload.
Idempotent methods plus 5xx are retryable with backoff. 400 is not. 409 is not a "try the same POST again" without reading the body.
Redirects: 301/308 keep the method (308) or historically change it (301/302 chaos). Clients should have an explicit follow policy. Infinite redirect loops need a cap (curl's default is finite).
C++: httplib puts the code on Result::status. libcurl: curl_easy_getinfo(..., CURLINFO_RESPONSE_CODE, &code). Beast: response.result_int() or response.result() as an enum. Do not parse the status line yourself unless you are writing a parser.
A server framework's default is often 200 if you forget to set it. Set it. Helpers (crow::response(404)) make that visible.
Do not invent 600. Stay in the IANA registry. Custom meaning belongs in the body.
HEAD responses have no body but have the same status and headers a GET would. Clients that treat "empty body" as failure will mis-handle HEAD.
Code Examples
#include <iostream>
bool ok(int status) { return status >= 200 && status < 300; }
bool retryable(int status) {
return status == 408 || status == 429 || status >= 500;
}
int main() {
std::cout << std::boolalpha << ok(204) << '\n'; // true
std::cout << retryable(503) << '\n'; // true
std::cout << retryable(400) << '\n'; // false
}#include <httplib.h>
int fetchStatus(httplib::Client& cli) {
auto res = cli.Get("/health");
if (!res) return -1; // transport failure, not an HTTP code
return res->status;
}
int main() { return 0; }Common Gotchas
Treating transport failure as `500`
if curl cannot connect, there is no HTTP status. Keep a separate error type.
`301` + POST
many clients rewrite to GET. Use `308` if you meant "same method, new URL".
`204 No Content` is success
a client that requires a JSON body will break. Document empty successes.
Logging only the body
the status is the index. Log both.