Skip to content

Instantly share code, notes, and snippets.

@opsJson
Last active June 23, 2024 03:39
Show Gist options
  • Save opsJson/e135a11014759c57e3e92ac7006152bf to your computer and use it in GitHub Desktop.
Save opsJson/e135a11014759c57e3e92ac7006152bf to your computer and use it in GitHub Desktop.
Curl interface for lua
function fetch(url, options)
local command = "curl \"" .. url .. "\" --silent"
if options.method then
command = command .. " -X \"".. options.method .. "\""
end
if options.body then
local body = options.body:gsub("\"", "\\\"")
command = command .. " --data \"".. body .. "\""
end
if options.headers then
for name, value in pairs(options.headers) do
command = command .. " -H \"".. name .. ": " .. value .."\""
end
end
local handle = io.popen(command)
local result = handle:read("*a")
handle:close()
return result:sub(0, -2)
end
--[[/////////////////////////////////////
Testing:
////////////////////////////////////////]]
result = fetch("https://marketplace.ifood.com.br/v2/cardstack/search/results?alias=SEARCH_RESULTS_MERCHANT_TAB_GLOBAL&latitude=-23.5588276&longitude=-46.6599882&channel=IFOOD&size=20&term=" .. "pizza", {
method = "POST",
headers = {
["Content-Type"] = "application/json"
},
body = '{"supported-headers":["OPERATION_HEADER"],"supported-cards":["MERCHANT_LIST","CATALOG_ITEM_LIST","CATALOG_ITEM_LIST_V2","CATALOG_ITEM_LIST_V3","FEATURED_MERCHANT_LIST","CATALOG_ITEM_CAROUSEL","CATALOG_ITEM_CAROUSEL_V2","CATALOG_ITEM_CAROUSEL_V3","BIG_BANNER_CAROUSEL","IMAGE_BANNER","MERCHANT_LIST_WITH_ITEMS_CAROUSEL","SMALL_BANNER_CAROUSEL","NEXT_CONTENT","MERCHANT_CAROUSEL","MERCHANT_TILE_CAROUSEL","SIMPLE_MERCHANT_CAROUSEL","INFO_CARD","MERCHANT_LIST_V2","ROUND_IMAGE_CAROUSEL","BANNER_GRID","MEDIUM_IMAGE_BANNER","MEDIUM_BANNER_CAROUSEL","RELATED_SEARCH_CAROUSEL","ADS_BANNER"],"supported-actions":["catalog-item","merchant","page","card-content","last-restaurants","webmiddleware","reorder","search","groceries","home-tab"],"feed-feature-name":"","faster-overrides":""}'
})
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment