HTTP requests¶
Server-side bundle code can make HTTP requests with re.net.Http. Both
methods return a Future<HttpResponse> you can await:
var res = await re.net.Http.Get("https://api.example.com/status");
if (res.Ok)
{
Console.WriteLine(res.Text());
}
var post = await re.net.Http.Post(
"https://api.example.com/score",
"{\"score\": 42}",
["Content-Type: application/json"]
);
HttpResponse contains:
| Member | Meaning |
|---|---|
Status |
HTTP status code, 0 when the request never completed (ulong) |
Error |
curl error code, 0 on success (uint) |
RawHeader |
The raw response header block |
Body |
The response body as bytes (byte[]) |
Ok |
true when Error is 0 and Status is below 400 |
Text() |
The body decoded as UTF-8 |
Header(name) |
One response header value, or "" |
Both methods take an optional headers array of "Name: value" strings and
an optional timeout in milliseconds (default 30000). Post takes the
request body as a string.
Requests are only possible to the destinations listed in the bundle's
[Networking] allowed config (see
Bundle Config). A request to any other
destination fails with a curl error code and is reported in the server log.
Redirects are followed, but every destination a redirect points at is
checked against the allow list as well.
Warning
The response body is held in memory in full and handed to your code as one buffer. Do not pull large payloads on every tick