1module("helpers", package.seeall)
2
3local io = require("io")
4local http = require("socket.http")
5local string = require("string")
6
7base_url = "http://localhost"
8
9function get(uri)
10  return http.request(base_url .. uri)
11end
12
13function post(uri, body)
14  local function do_it(body)
15    local flat
16    if (type(body) == "table") then
17      i = 1
18      for k, v in pairs(body) do
19        if i == 1 then
20          flat = k .. "=" ..v
21        else
22          flat = flat .. "&" .. k .. "=" .. v
23        end
24        i = i + 1
25      end
26    else
27      flat = body;
28    end
29    return http.request(base_url .. uri, flat)
30  end
31  if body then
32    return do_it(body)
33  else
34    return do_it
35  end
36end