FFGFlash

api/request.lua

Sep 28th, 2021 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.54 KB | None | 0 0
  1. local api = { LoadOrder = 0 }
  2. function api.Build()
  3.   local Request = {}
  4.   function Request.encode(...) local r = {} for i,s in ipairs({...}) do r[#r+1]=textutils.urlEncode(s) end return table.unpack(r) end
  5.   function Request:parseParams(p) local r = {} for k,v in pairs(p) do r[#r+1]=k.."="..self.encode(v) end return table.concat(r,"&") end
  6.   function Request:post(u,p,h) return http.post(u,self:parseParams(p or {}),h) end
  7.   function Request:get(u,p,h) return http.get(u.."?"..self:parseParams(p or {}),h) end
  8.   return Request
  9. end
  10. return api
Add Comment
Please, Sign In to add comment