-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
51 lines (42 loc) · 1.04 KB
/
client.lua
File metadata and controls
51 lines (42 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env tarantool
assert(arg[1], 'URL is required')
assert(arg[2], 'Command is required')
local http_client = require('http.client')
local json = require('json')
local function post()
assert(arg[3], 'Key is required')
assert(arg[4], 'Value is required')
local r = http_client.post(arg[1]..'kv', json.encode({key = arg[3], value = arg[4]}))
print(r.status)
end
local function put()
assert(arg[3], 'id is required')
assert(arg[4], 'Value is required')
local r = http_client.put(arg[1]..'kv/'..tostring(arg[3]), json.encode({value = arg[4]}))
print(r.status)
end
local function get()
assert(arg[3], 'id is required')
local r = http_client.get(arg[1]..'kv/'..tostring(arg[3]))
print(r.status)
if(r.status == 200) then
print(r.body)
end
end
local function delete()
assert(arg[3], 'id is required')
local r = http_client.delete(arg[1]..'kv/'..tostring(arg[3]))
print(r.status)
end
if(arg[2] == 'GET') then
get()
end
if(arg[2] == 'POST') then
post()
end
if(arg[2] == 'PUT') then
put()
end
if(arg[2] == 'DELETE') then
delete()
end