---
title: "http"
description: "Asynchronous HTTP requests with callbacks on the client thread."
---

> Documentation Index
> Fetch the complete documentation index at: https://aesthetic-docs.pages.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# http

Requests never block the game: the callback fires later on the client thread with a response
table, or with `nil` and an error message when the request fails at the network level (an HTTP
error status is still a response — check `ok`). Callbacks of an unloaded script are dropped.

| Function | Does |
|----------|------|
| `http.get(url, callback[, headers])` | `GET` request |
| `http.post(url, body, callback[, headers])` | `POST` request with a string body |
| `http.request(opts, callback)` | Any method: `opts = { url, method, body, headers, timeout }` |

`timeout` is in seconds (default `10`). Redirects are followed.

## Response

| Field | Value |
|-------|-------|
| `status` | HTTP status code |
| `ok` | `true` for `2xx` |
| `body` | Response body as a string |
| `headers` | Table of lowercased header names; repeated values joined with `, ` |

```lua
http.get("https://api.mojang.com/users/profiles/minecraft/Notch", function(res, err)
if not res then
    aesthetic.log("request failed: " .. err)
elseif res.ok then
    aesthetic.log(res.body)
end
end)

http.request({
url = "https://example.com/hook",
method = "PUT",
body = '{"hello":"world"}',
headers = { ["Content-Type"] = "application/json" },
}, function(res) end)
```

Source: https://aesthetic-docs.pages.dev/http/index.md
