├── README.md └── v1 ├── documentation ├── authentication.md ├── request.md └── response.md └── index.md /README.md: -------------------------------------------------------------------------------- 1 | # Architecting an API 2 | 3 | ## Versioning 4 | APIs should be properly versioned. APIs evolve and change, we must do this while supporting 5 | old versions. Otherwise, if you just change your API, a lot of your clients would be in trouble. 6 | Although, we won't be developing multiple versions (today we're working on V1), it is important 7 | that we plan for the future and properly namespace our documentation and work under V1 namespace. 8 | -------------------------------------------------------------------------------- /v1/documentation/authentication.md: -------------------------------------------------------------------------------- 1 | # Authentication 2 | 3 | ## API Key 4 | 5 | Every user must obtain a public API key to make requests. 6 | This key is sent in clear text along with every request. 7 | 8 | The parameter name is `api_key`. 9 | 10 | ## API Secret Token 11 | 12 | Every user receives a companion private secret token. This string is used as a 13 | salt in generating request signatures and is never sent in clear text. 14 | 15 | The parameter name is `secret`. 16 | -------------------------------------------------------------------------------- /v1/documentation/request.md: -------------------------------------------------------------------------------- 1 | # Requests 2 | 3 | All requests are made on a specific API resource: 4 | 5 | https://api.aventura/v1/[resource] 6 | 7 | The clear-text parameters in each requests must be accompanied by three 8 | additional parameters: an _API key_, a _request signature_, and a _timestamp_. 9 | The request signature is generated using a _secret token_, a _timestamp_. 10 | 11 | ## Content Type 12 | 13 | The body of POST and PUT requests, including any relevant parameters, can be 14 | formatted as URL-encoded form data or Javascript Object Notation (JSON). The 15 | format is specified in the `Content-Type` HTTP header of a request. 16 | 17 | The API assumes that the body of a request is URL-encoded form data unless a 18 | `Content-Type` header is specified. The following Content-Type headers are 19 | accepted: 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
FormatMIME Type
URL-encoded form data`application/x-www-form-urlencoded`
JSON`application/json`
37 | 38 | ## Request Validation 39 | 40 | ### Timestamp 41 | 42 | Every request must include a timestamp parameter with the UTC current date and time 43 | in UNIX format. This parameter is both sent in clear text for verification 44 | and included in the request signature as a salt. Requests submitted more than 10 45 | minutes before or after the date and time indicated by the timestamp will be 46 | rejected. 47 | 48 | ### Endpoint 49 | 50 | The endpoint -- the path to which the HTTP request is made -- is included only 51 | as a parameter in the request signature as a salt. 52 | 53 | ### Request Signature 54 | 55 | Every request must include a request signature parameter, appended to the 56 | clear-text parameters as rsig. This ensures that the request originated from an 57 | authorized API user and, if applicable, that the user is authorized to perform 58 | the requested action. 59 | 60 | The request signature consists of the hexadecimal SHA-2 digest of the 61 | alphabetized parameters in URL-encoded query string format. The parameters used 62 | to construct the signature are all those that are required for the specific 63 | request, including the API key, along with the requestor’s secret token, the 64 | timestamp, the endpoint 65 | 66 | #### Request Signature Parameters 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 |
Parameter NameDescriptionExample
api_keyThe user’s API key.754a28309b20012f479b109add670a2c
secretThe API user’s secret token.003af2309b1f012f479b109add670a2c
timestamp 87 | The timestamp of the request in ISO 8601 format: 88 | YYYY-MM-DDThh:mmTZD 89 | 2012-04-18T21:02-07:00
endpointThe path of the endpoint to which the API request is sent./v1/resorts/48503
VariesAll other clear-text parameters for the specific request.api_key=754a28309b20012f479b109add670a2c&resort_id=2&package_id=10&
105 | 106 | For example, when making a call to retrieve information about a resort, the clear-text parameters would be 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 |
Parameter NameDescriptionExample
api_keyThe user’s API key.754a28309b20012f479b109add670a2c
resort_idThe resort to fetch information about.4832
timestampThe timestamp of the request in ISO 8601 format: YYYY-MM-DDThh:mmTZD2014-04-18T21:12-00:00
132 | 133 | 134 | As an example, to construct the request signature for this request, we start with the clear-text parameters in alphabetical order by name: 135 | 136 | api_key=754a28309b20012f479b109add670a2c&resort_id=4832 137 | 138 | The secret token and timestamp are then added, in alphabetical order, as additional parameters. Then the whole string is URL-encoded: 139 | 140 | api_key=754a28309b20012f479b109add670a2c&endpoint=https%3A%2F%2Fapi.aventura%2Fv1%2Fresorts%2F48503&resort_id=4832&secret=003af2309b1f012f479b109add670a2c×tamp=2014-04-18T21%3A12-00%3A00 141 | 142 | And the final request signature would be the SHA-2 digest of the string above: 143 | 144 | 681f9129c435e2af7c434c76e28db3921e1518956656d926f6124cc93a47c213 145 | 146 | The signature is then appended as a parameter, `rsig`, to the clear-text query string. So the full request and return value would be 147 | 148 | GET https://api.aventura/v1/resorts/4832?api_key=754a28309b20012f479b109add670a2c&rsig=1d12d0b923ecdbb4d5b1df8c7f2f1b3c2270bc6e538bbf5d32611d3429c1b310×tamp=2014-04-18T21%3A12-00%3A00 149 | 150 | => { 151 | "name": "Resort Rio", 152 | "url": "http://www.aventura/resorts/rio-hotel", 153 | "description": "great resort in the heart of Rio", 154 | ... 155 | } 156 | -------------------------------------------------------------------------------- /v1/documentation/response.md: -------------------------------------------------------------------------------- 1 | # Responses 2 | 3 | Depending on its type, a request is either processed immediately or queued for 4 | processing later. Generally, requests that are seeking information will get an 5 | immediate response; requests that are modifying or adding data will be queued 6 | for later. 7 | 8 | ## Response Codes 9 | 10 | The following HTTP status codes are possible in response to a request: 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | 26 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 57 | 58 | 59 | 60 | 61 | 63 | 64 | 65 | 66 | 67 | 69 | 70 | 71 | 72 | 73 | 75 | 76 | 77 |
HTTP Status CodeStatusDescription
200OK (Immediate response)The request was a success and the response includes the 22 | requested data.
202OK (Immediate response)The request was received and queued for processing, but not yet 28 | processed.
400Bad RequestThe request was malformed or unexpected.
401UnauthorizedThe request did not include a valid API key, secret, or resort 39 | authorization key.
403ForbiddenThe request included an API key, secret, or a resort 45 | authorization key that has been revoked.
404Not FoundThe requested resource was not found.
415Unsupported Media TypeThe request was sent with a specified format that is not 56 | supported.
429Too Many RequestsThe rate limit has been reached for this API key. See Rate 62 | Limits.
500Internal Server ErrorThe request could not be fulfilled due to an unexpected 68 | error.
503Service UnavailableAventura is temporarily unable to fulfill the request. The 74 | request can be tried again later.
78 | 79 | ## Response Format 80 | 81 | All responses are sent in JSON. 82 | -------------------------------------------------------------------------------- /v1/index.md: -------------------------------------------------------------------------------- 1 | * [Getting Started](getting_started.md) 2 | * Obtain an API Key and Secret Token 3 | * Rate Limits 4 | * [Requests](requests.md) 5 | * Content Type 6 | * Request Validation 7 | * Timestamp 8 | * Endpoint 9 | * Request Signature 10 | * [Responses](responses.md) 11 | * Response Codes 12 | * Response Format 13 | * [Authentication](authentication.md) 14 | * API Key 15 | * API Secret Token 16 | * [Resources](resources.md) 17 | * Products 18 | * ... 19 | --------------------------------------------------------------------------------