Serve /all

This commit is contained in:
Christine Dodrill 2015-08-13 19:47:00 -07:00
parent 71489f4f33
commit 162052d17b
2 changed files with 38 additions and 2 deletions

View File

@ -1,5 +1,5 @@
build:
nim c -d:release --deadcodeElim:on --hints:off ponyapi
nim c --deadcodeElim:on --hints:off ponyapi
run: build
./ponyapi

View File

@ -1,3 +1,4 @@
import asyncdispatch
import jester
import json
import strutils
@ -32,4 +33,39 @@ for line in lines "./fim.list":
episodes = episodes & ep
echo episodes
proc `%`(ep: Episode): JsonNode =
%*
{
"name": ep.name,
"air_date": ep.air_date,
"season": ep.season,
"episode": ep.episode,
"is_movie": ep.is_movie,
}
proc `%`(eps: seq[Episode]): JsonNode =
var ret = newJArray()
for ep in episodes:
add ret, %ep
ret
settings:
port = 5000.Port
bindAddr = "0.0.0.0"
routes:
get "/":
"http://github.com/Xe/PonyAPI".uri.redirect
get "/all":
let headers = {"Content-Type": "application/json"}
var rep = %*
{
"episodes": episodes,
}
resp Http200, headers, pretty(rep, 4)
runForever()