Created
July 24, 2014 18:27
-
-
Save rtsisyk/98a8f57aaa1152a86873 to your computer and use it in GitHub Desktop.
Tarantool HTTP Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env tarantool | |
box.cfg{} | |
space = box.space.data | |
if not space then | |
space = box.schema.create_space('data') | |
space:create_index('primary', { parts = {1, 'STR'} }) | |
end | |
local function handler(self) | |
local host = self.req.peer.host | |
local response = { | |
host = host; | |
counter = space:inc(host); | |
} | |
self:render({ json = response }) | |
end | |
require('http.server').new('127.0.0.1', 8080) | |
:route({ path = '/' }, handler) | |
:start() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually there is issue with your code. You forgot 'return'.
Correct handler function looks like: