├── 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 | Format |
24 | MIME Type |
25 |
26 |
27 |
28 | URL-encoded form data |
29 | `application/x-www-form-urlencoded` |
30 |
31 |
32 | JSON |
33 | `application/json` |
34 |
35 |
36 |
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 | Parameter Name |
70 | Description |
71 | Example |
72 |
73 |
74 |
75 | api_key |
76 | The user’s API key. |
77 | 754a28309b20012f479b109add670a2c |
78 |
79 |
80 | secret |
81 | The API user’s secret token. |
82 | 003af2309b1f012f479b109add670a2c |
83 |
84 |
85 | timestamp |
86 |
87 | The timestamp of the request in ISO 8601 format:
88 | YYYY-MM-DDThh:mmTZD
89 | |
90 | 2012-04-18T21:02-07:00 |
91 |
92 |
93 | endpoint |
94 | The path of the endpoint to which the API request is sent. |
95 | /v1/resorts/48503 |
96 |
97 |
98 |
99 | Varies |
100 | All other clear-text parameters for the specific request. |
101 | api_key=754a28309b20012f479b109add670a2c&resort_id=2&package_id=10& |
102 |
103 |
104 |
105 |
106 | For example, when making a call to retrieve information about a resort, the clear-text parameters would be
107 |
108 |
109 |
110 | Parameter Name |
111 | Description |
112 | Example |
113 |
114 |
115 |
116 | api_key |
117 | The user’s API key. |
118 | 754a28309b20012f479b109add670a2c |
119 |
120 |
121 | resort_id |
122 | The resort to fetch information about. |
123 | 4832 |
124 |
125 |
126 | timestamp |
127 | The timestamp of the request in ISO 8601 format: YYYY-MM-DDThh:mmTZD |
128 | 2014-04-18T21:12-00:00 |
129 |
130 |
131 |
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 | HTTP Status Code |
14 | Status |
15 | Description |
16 |
17 |
18 |
19 | 200 |
20 | OK (Immediate response) |
21 | The request was a success and the response includes the
22 | requested data. |
23 |
24 |
25 | 202 |
26 | OK (Immediate response) |
27 | The request was received and queued for processing, but not yet
28 | processed. |
29 |
30 |
31 | 400 |
32 | Bad Request |
33 | The request was malformed or unexpected. |
34 |
35 |
36 | 401 |
37 | Unauthorized |
38 | The request did not include a valid API key, secret, or resort
39 | authorization key. |
40 |
41 |
42 | 403 |
43 | Forbidden |
44 | The request included an API key, secret, or a resort
45 | authorization key that has been revoked. |
46 |
47 |
48 | 404 |
49 | Not Found |
50 | The requested resource was not found. |
51 |
52 |
53 | 415 |
54 | Unsupported Media Type |
55 | The request was sent with a specified format that is not
56 | supported. |
57 |
58 |
59 | 429 |
60 | Too Many Requests |
61 | The rate limit has been reached for this API key. See Rate
62 | Limits. |
63 |
64 |
65 | 500 |
66 | Internal Server Error |
67 | The request could not be fulfilled due to an unexpected
68 | error. |
69 |
70 |
71 | 503 |
72 | Service Unavailable |
73 | Aventura is temporarily unable to fulfill the request. The
74 | request can be tried again later. |
75 |
76 |
77 |
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 |
--------------------------------------------------------------------------------