HTTP request module


  • Lately a lot of people have been asking me a lot of questions about how to do HTTP requests and I find myself writing the same code over and over but with small changes to fit the api / endpoint requirements. Since all requests need to be formatted is the same way per request type the whole process can be simplified into a module.

    The HTTP module can be found here (requires some testing atm).

    API

    The base url for each request, returns a requestObject 
    requestObject Constructor(baseUrl string)
    
    requestObject 
    
    Reforms a get request with the given data 
    array[result, data] Get(data table or string, [appendToUrl string optional])
    
    Reforms a post request with the given data 
    array[result, data] Post(data table or string, [appendToUrl string optional])
    
    Sets the headers to be passed in a get request
    SetGetHeaders(headers table or nil)
    
    Sets the headers to be passed in a post request
    SetPostHeaders(headers table or nil)
    
    Sets the non cached flag for a get request
    SetGetCached(notCached boolean)
    
    Sets the post content type
    SetPostContentType(contentType string)
    
    Sets if post requests use compression
    SetPostCompress(isCompressed boolean)
    

    Example code

    local request = require(script.Parent.HTTPRequestModule)('http://google.co.uk')
    
    request:SetGetCached(false)
    print(unpack(request:Get()))
    
    print(unpack(request:Get({q='cat'}, '/search'))) -- append the /search to the url
    

    Please comment if there is anything that could be included or updated.


  • First off, this would actually help beginners with using HttpService, good job! Second off, when I press the link to the module it says Page Not Found.


  • @mccrafter1212 It seems like roblox has changed how its site works 0_o. Link fixed.

Log in to reply
 

Looks like your connection to Scripting Helpers was lost, please wait while we try to reconnect.