Sending the PATCH request and receiveing the HTTP response is done by a Task asynchronously (other Tasks will be executed concurrently without blocking execution flow)
Http:patch(uri, content)
Send an asynchronous PATCH request to the connected HTTP server to apply partial modifications to the target resource.
Parameters
uri
A string
representing the target resource on the server.
content
A File or any value converted to a string
representing the body content of the request.
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 PUT 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"
local client = net.Http("https://reqbin.com")
local data = [[
{
"User": {
"Id": 12345,
"Name": "John Smith"
}
}
]]
-- make a PATCH request, and once its terminated, call the provided function, to process the response
client:patch("/echo/patch/json", data).after = function (self, response)
if not response then
error(net.error)
end
print(response.content)
end
waitall()