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:
parent
791b7d59a0
commit
882b5b1551
|
@ -51,9 +51,16 @@ 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.
|
||||
resp code, myHeaders, pretty(%%body, 4)
|
||||
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 = {
|
||||
"Content-Type": "application/json",
|
||||
|
|
Loading…
Reference in New Issue