Nim 0.14 update

This commit is contained in:
Cadey Ratio 2016-07-02 21:53:36 -07:00
parent fac0d25655
commit a669ee2018
2 changed files with 8 additions and 17 deletions

View File

@ -1,6 +1,7 @@
import asyncdispatch import asyncdispatch
import episode import episode
import future import future
import httpcore
import jester import jester
import json import json
import os import os
@ -58,16 +59,9 @@ template httpReply(code, body: expr): expr =
## Make things a lot simpler for replies, etc. ## Make things a lot simpler for replies, etc.
if request.headers.getOrDefault("X-API-Options") == "bare" or @"options" == "bare": if request.headers.getOrDefault("X-API-Options") == "bare" or @"options" == "bare":
# New "bare" reply format, easier to scrape, etc. # New "bare" reply format, easier to scrape, etc.
resp code, myHeaders, pretty(%body, 4) resp code, "application/json", pretty(%body, 4)
else: else:
resp code, myHeaders, pretty(%%body, 4) resp code, "application/json", pretty(%%body, 4)
let myHeaders = {
"Content-Type": "application/json",
"X-Powered-By": "Nim and Jester",
"X-Git-Hash": getEnv("GIT_REV"),
"X-Server-Epoch": $ getTime().toSeconds().int,
}
settings: settings:
port = 5000.Port port = 5000.Port
@ -102,7 +96,7 @@ routes:
get "/random": get "/random":
stats.newest.success.inc stats.newest.success.inc
httpReply Http200, episodes.randomChoice() httpReply Http200, episodes[epochTime().int mod len(episodes)]
get "/last_aired": get "/last_aired":
var var
@ -160,7 +154,7 @@ routes:
if query == "": if query == "":
stats.search.fails.inc stats.search.fails.inc
halt Http406, myHeaders, pretty(%%"Need to specify a query", 4) halt Http406, pretty(%%"Need to specify a query", 4)
var var
eps: seq[Episode] = eps: seq[Episode] =
@ -174,7 +168,7 @@ routes:
httpReply Http200, eps httpReply Http200, eps
get "/_stats": get "/_stats":
resp Http200, myHeaders, pretty(%* resp Http200, pretty(%*
[ [
stats.all, stats.all,
stats.newest, stats.newest,

View File

@ -1,10 +1,7 @@
[Package]
name = "ponyapi"
version = "0.1.0" version = "0.1.0"
author = "Christine Dodrill <xena@yolo-swag.com>" author = "Christine Dodrill <xena@yolo-swag.com>"
description = "PonyAPI server https://github.com/Xe/PonyAPI" description = "PonyAPI server https://github.com/Xe/PonyAPI"
license = "MIT" license = "MIT"
bin = "ponyapi" bin = @["ponyapi"]
[Deps] requires "nim >= 0.10.0", "jester#head", "random"
Requires: "nim >= 0.10.0, jester#head, random#head"