Roblox Requests: Simple, powerful HTTP in Roblox

Roblox Requests is a simple and elegant yet powerful HTTP library, based on the well known Python Requests.

local r = http.get("https://api.github.com/orgs/Roblox/repos")

print(r.status_code, r.message)
-- 200 OK

local repos = r:json()
print(#repos)
-- 30

print(r.content_type)
-- application/json
print(r.encoding)
-- utf-8
print(r.headers["x-ratelimit-remaining"])
-- 59

The main purpose of Requests is to avoid the manual labor of HttpService.
Consider this code comparison: httpservice.lua · GitHub

This isn’t all that Requests is good for. Here’s some other features that will make your life easier:

  • Functions for every HTTP verb
  • DOM parser allows you to navigate HTML, XML
  • Sessions with cookie persistence, base URLs/headers
    • Configurable rate-limiting to help you balance your game’s HTTP usage
  • Automatic query string building, JSON body encoding
  • Accessible Response object with useful data, builtin JSON decoding
  • Multipart form building, including file encoding and upload
  • Domain based key/value cookies
  • Local and Global Response Caching
    • DataStore and MessagingService backed global cache for large resources
  • Builtin support for Promises

How To Install

You can find full documentation at https://requests.paric.xyz/. If you have any suggestions or bug reports, feel free to let me know here or contribute on the GitHub page, or join my Discord: paric's potatoes

67 Likes

Promise Support

Roblox Requests now supports Roblox Lua Promises. I think this addition will make the library more useful to many Roblox devs looking for a more robust solution for HTTP requests in Roblox.

Here’s an example of using the library’s existing methods with Promises:

http.promise_get("https://api.github.com/orgs/this_org_does_not_exist/repos")
    :andThen(function(response)
        for _, repo in ipairs(response:json()) do
            print(repo.name)
        end
    end)
    :catch(function(err)
        if err.request_sent then
            print("HTTP Error:", err.response.status_code, err.response.message)
        else
            print(err.error)
        end
    end)

    -- HTTP Error: 404 Not Found

For more info on using Promises, see the project documentation:

Full changelog and module download:

4 Likes

HTML/XML Parsing

Roblox Requests will now generate a DOM for you from HTML/XML response content or a string, powered by lua-htmlparser.

A full guide for this functionality can be found at HTML/XML Parsing - Roblox Requests.

Here’s an example use case that finds all the links on GitHub’s front page:

local document = http.get("https://github.com"):html()

for _, url in ipairs(document:absolute_links()) do
    print(url)
end

-- https://github.com/#start-of-content
-- https://help.github.com/articles/supported-browsers
-- https://github.com/
-- https://github.com/join?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F&source=header-home
-- ...
6 Likes

Woah, this is a very convenient and useful Roblox module. It may be one of the only modules that I use in my actual work.

This relieves a lot of my stressful API work that is handled on my own site due to Roblox being to send advanced requests.

4 Likes

Update 0.5

Roblox Requests 0.5 adds response caching and fixes several breaking bugs.

The binary for this version can be downloaded here:

New

Deprecated

  • http.send(…) renamed to http.request(…)
  • session:send(…) renamed to session:request(…)

Bug Fixes

  • HTML/XML parser shouldn’t freeze when parsing large files
  • fixed issue where malformed JSON errors wouldn’t be logged properly
  • no longer breaks on responses with no content-type header
2 Likes

update: just pushed a small bug fix for 0.5! If you use any of the promise_ methods from 0.5.1, they will throw a deprecated method warning. Fix by updating to the latest release: Release 0.5.4: Merge pull request #18 from jpatrickdill/dev · jpatrickdill/roblox-requests · GitHub

1 Like

Wow, this library’s a hidden gem! As a big fan of the Python requests library, I’m in love already :slight_smile:

I noticed a tiny issue with sending files using multipart/form-data, wherein extra \r\n was preceding my data. I submitted an issue (#16) and a pull request which fixes it over on GitHub. It was causing me trouble while using the Telegram Bot API’s sendDocument method.

2 Likes

Would this presumably work properly or well alongside my node and .js coded bot on repl?

1 Like

If you’re talking about importing the Roblox Requests module into repl then no, It will not work that was as repl does not have support for Roblox Engine API’s like HttpService.

If you’re asking if you can use Roblox Requests to communicate with your API deployed on repl then yes. Roblox Requests is just a wrapper of HttpService that allows you to more easily write and handle requests.

2 Likes