local http = require("http")
local json = require("json")
-- API returns a JSON containing our pets and prices:
response, error_message = http.request("GET", "https://gist.githubusercontent.com/rusenask/c1b5840c62a70ea11fdedd9a6aabbd03/raw/8a0177791d94c22fdb9345243392c62ddb10a10f/pets.json")
if error_message then error(error_message) end
-- Parsing response body from the API
local api_response, err = json.decode(response.body)
if err then error(err) end
local request_body, err = json.decode(r.RequestBody)
if err then error(err) end
local message = "Purchased pet: " ..
request_body["pet"] .. " | quantity: " ..
request_body["quantity"] .. " | total:" .. request_body["quantity"] * api_response[request_body["pet"]]["price"]
local encoded_payload, err = json.encode(new_payload)
if err then error(err) end
-- Set request header to application/json
r:SetRequestHeader("Content-Type", "application/json")
-- Set request method to PUT
r:SetRequestMethod("PUT")
-- Set modified request body
r:SetRequestBody(encoded_payload)