From c050b65bbf2be5e04981f1ee101a46b8390054f2 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Tue, 8 Sep 2015 16:23:22 -0700 Subject: [PATCH] Add X-API-Options documentation --- README.md | 25 +++++++++++++++++++++++++ ponyapi.nim | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cd22c7f..7d131e5 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,31 @@ $ curl http://ponyapi.apps.xeserv.us/season/1/episode/1 } ``` +Bare Replies +------------ + +As of [882b5b1](https://github.com/Xe/PonyAPI/commit/882b5b155157d3a3c9e329fffcf7ff3fdf64d4ee), +PonyAPI will accept an `X-API-Options` header that when set to `bare` will +return the API replies without the `episode` or `episodes` header. +Functionality is otherwise unchanged, however an error will still be shown if +something goes wrong, and that will parse differently. This API will return +`200` if and **only** if everything went to plan. + +An example: + +```console +$ curl --header "X-API-Options: bare" http://ponyapi.apps.xeserv.us/last_aired +{ + "name": "Do Princesses Dream of Magic Sheep?", + "air_date": 1436628600, + "season": 5, + "episode": 13, + "is_movie": false +} +``` + +This will also be triggered if you set the query parameter `options` to `bare`. + ### `/all` Returns all information about all episodes. This returns an array of Episode diff --git a/ponyapi.nim b/ponyapi.nim index 0e2bdcf..73c22b7 100644 --- a/ponyapi.nim +++ b/ponyapi.nim @@ -56,7 +56,7 @@ proc `%`(why: string): JsonNode = template httpReply(code, body: expr): expr = ## Make things a lot simpler for replies, etc. - if request.headers["X-API-Options"] == "bare": + if request.headers["X-API-Options"] == "bare" or @"options" == "bare": # New "bare" reply format, easier to scrape, etc. resp code, myHeaders, pretty(%body, 4) else: