Skip to content

Commit

Permalink
add a more realistic teaser
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Hundt committed Dec 15, 2014
1 parent d462595 commit 502409e
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@

```Lua
import like from "util.guards"
-- taken from a real world web app which talks to elasticsearch

Shiny = like { luminosity = Number }
import JSON from "codec.json"
import Presenter from "swarm.app"
import HTTPStatic from "swarm.static"

function bling(what is Shiny)
print "\u2606\u20AC %{what.luminosity} \u20AC\u2606"
end
import ESClient, ESIndex from "app.es.client"

-- this presenter is a singleton, so we use `module` here
module Features include Presenter

local client = ESClient('localhost', 9200)
local storage = ESIndex(client, 'features')
local static = HTTPStatic("./public/admin")

@self.route('GET', '/admin')
admin(req, path, query)
if #path == 0 then
path[#path + 1] = 'index.html'
end
return static.handler(req, path, query)
end

bling { luminosity = 42 }
@self.route('GET', '/features/feature/:id')
fetch(req, args, query)
resp = storage.lookup('feature', args['id'])
hdrs = { }
hdrs['Content-Type'] = 'application/json'
if resp.exists then
return { 200, hdrs, { JSON.encode(resp) } }
else
return { 404, hdrs, { JSON.encode(resp) } }
end
end

end
```

# Shine Reference
Expand Down

0 comments on commit 502409e

Please sign in to comment.