Advertisement
Guest User

relay.post.lua

a guest
Mar 3rd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.54 KB | None | 0 0
  1. return function(req, res)
  2.  res:addheader("Content-Type", "application/json; charset=utf-8")
  3.  
  4.  if req.body then
  5.  
  6.   local success, json = pcall(cjson.decode, req.body)
  7.   if not success then
  8.    error(json)
  9.   end
  10.   -- Decode json object from body
  11.   if (json.pin ~= nil) then
  12.    res:send(cjson.encode({status = "sucsess",pin = json.pin}))
  13.    return
  14.   end
  15.  end
  16.  
  17.  res.statuscode = 400
  18.  -- Create and encode result as json string
  19.  local result = { code = 400, description = "Wrong API call" }
  20.  res:send(cjson.encode(result))
  21.  
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement