Sending the GET request and receiveing the HTTP response is done by a Task asynchronously (other Tasks will be executed concurrently without blocking execution flow)
Http:get(uri, [parameters])
Send an asynchronous GET request to the connected HTTP server for a specific resource.
Parameters
uri
A string representing the resource to get on the server.
[parameters]
An optional table
that contains parameters to be sent with the request, in the form of key1=value1&key2=value2
...
Return value
This method return a Task instance. Once the Task has finished, it will return two values :
- The first value is the Http instance used for the GET request.
- The second value is
nil
in case of error or atable
that contains the server response, with the following fields "content"
: astring
containing the body part of the HTTP response"elapsed"
: anumber
representing the elapsed time to get the response"status"
: anumber
containing the HTTP response status"reason"
: astring
containing HTTP response status text"ok"
: aboolean
value indicating if the GET request succeeded"headers"
: atable
containing a pair ofstrings
(header field names of the HTTP response as key and content as values)"cookies"
: atable
containing a pair ofstrings
(cookies names of the HTTP response as key and content as values)
Example
local net = require "net"
-- creates a Http instance and call its get() method
-- the get() method will return a Task instance
-- then we set the Task instance "after" property
-- with a function that will be called once the Task is terminated, using the two values returned by the Task
net.Http("https://wttr.in"):get("/Paris?format=3").after = function (client, response)
console.write(response.content)
end
waitall()