Summary#
HttpResponse is what every Http.* verb (Http.*) returns. It has three fields:
| Field | Type | Meaning |
|---|---|---|
StatusCode | int | The HTTP status code — 200, 404, 500, … |
Body | string | The response body as UTF-8 text |
IsSuccess | bool | true when the status is in the 2xx range |
A non-2xx response is a normal return, so you inspect it rather than catch an error:
use Osyrin.Http;
var r = Http.Get(url);
if (r.IsSuccess) {
Process(r.Body);
} else {
Log("fetch failed with " + r.StatusCode);
}Signature#
class HttpResponse {
int StatusCode;
string Body;
bool IsSuccess;
}The type enters scope with the same dependency that enables the facade — use Osyrin.Http;. You rarely name it
explicitly: var r = Http.Get(url); infers it.
Description#
Body is always text. When the endpoint returns JSON, parse Body with the JSON surface; HttpResponse doesn't
assume a format — it hands you the bytes as a string and the status to decide what to do with them.
IsSuccess is exactly 200 ≤ StatusCode < 300. It's a convenience for the common "did it work?" branch; when you
care about a specific code (a 429 to back off, a 404 to treat as absent), read StatusCode directly.
Examples#
Distinguish "not found" from a real failure:
app Shop {
model "model/**/*.osy";
use Osyrin.Http; // the manifest dependency that makes `Http.*` available
}
string FetchOrEmpty(string url) {
var r = Http.Get(url);
if (r.StatusCode == 404) return ""; // absent — expected
if (!r.IsSuccess) return ""; // some other failure
return r.Body;
}See also#
- Http.* — the
Http.Get/Post/Put/Deleteverbs that return this type