Add new X-API-Options header for bare replies

Setting X-API-Options to bare will return unpacked values.

    $ curl --header "X-API-Options: bare" http://127.0.0.1:5000/last_aired
    {
        "name": "Do Princesses Dream of Magic Sheep?",
        "air_date": 1436628600,
        "season": 5,
        "episode": 13,
        "is_movie": false
    }
This commit is contained in:
Christine Dodrill 2015-09-08 15:48:06 -07:00
parent 791b7d59a0
commit 882b5b1551
1 changed files with 8 additions and 1 deletions

View File

@ -51,8 +51,15 @@ proc `%%`(why: string): JsonNode =
"error": why
}
proc `%`(why: string): JsonNode =
%%why
template httpReply(code, body: expr): expr =
## Make things a lot simpler for replies, etc.
if request.headers["X-API-Options"] == "bare":
# New "bare" reply format, easier to scrape, etc.
resp code, myHeaders, pretty(%body, 4)
else:
resp code, myHeaders, pretty(%%body, 4)
let myHeaders = {