This repository was archived by the owner on Oct 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiary.apib
More file actions
334 lines (257 loc) · 9.05 KB
/
apiary.apib
File metadata and controls
334 lines (257 loc) · 9.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
HOST: https://air-monitor.pl
# AirMonitor
AirMonitor is a simple API for air pollution measurement system. Source code is available on [GitHub](https://github.com/mckomo/AirMonitor).
## Authorization
Main goal of the *AirMonitor* is to make information about air pollution widely available, thus *read* operations do not require any form of authorization.
However if you interested in sharing your own data you will be required to register a new account.
E-mail and password used during registration process will necessary credentials to obtain an [access token](#access-token-post).
Access token is used in form of the **Bearer token** and must be placed in `Authorization` header for each restricted API request.
Example of such a header is shown below.
```
Authorization: Bearer AUTH_TOKEN
```
## Errors
During API usage you may stumble upon a request error. If a HTTP response has `4xx` or `5xx` status code you should expect an error with the following format:
```
{
"message": "Unauthorized access error",
"exception": {},
"code": 401
}
```
### Validation errors
When `POST` or `PUT` request has failed and resulted in `422` HTTP status code you should expect a validation error that contains a validation message for each invalid field.
```
{
"name": [
"can't be blank"
],
"user": [
"must exist",
]
}
```
## Access token [/api/v1/auth/token]
### Create Access Token [POST]
Obtain an access token that is required for *nonread* operations.
+ Request (application/json)
{
"auth":{
"email": "mckomo@gmail.com",
"password": "MyPassword"
}
}
+ Response 201 (application/json)
{
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJmN2JmODVkNC0xYTZmLTw4MWQtYjhkNC0zNDliYWZhNDExYzMifQ.DyDxMfMoHfaLTuq-qAAwAfoh-rgCHTcA5Knsy4oIZvw"
}
## User [/api/v1/me]
### View a User Profile [GET]
Get specific measurement station.
+ Response 200 (application/json)
{
"id": "f7bf85d4-1a6f-481d-b8d4-349bafa411c3",
"name": "Mckomo",
"email": "mckomo@gmail.com",
"joined_at": "2016-01-02T17:51:08.507Z"
}
## Stations Collection [/api/v1/stations]
### List All Stations [GET]
List all measurement stations.
+ Response 200 (application/json)
[
{
"id":"13f99447-dd96-4ee9-b218-191a9a1c1416",
"code":"PL0012A",
"name":"Kraków, Aleja Krasińskiego",
"latitude":50.057678,
"longitude":19.926189
}
]
## Station [/api/v1/stations/{station_id}]
+ Parameters
+ station_id (uuid) - ID of the Station
### View a Station Detail [GET]
Get specific measurement station.
+ Response 200 (application/json)
{
"id":"13f99447-dd96-4ee9-b218-191a9a1c1416",
"code":"PL0012A",
"name":"Kraków, Aleja Krasińskiego",
"latitude":50.057678,
"longitude":19.926189,
"created_at":"2015-12-28T21:46:17.258Z",
"updated_at":"2015-12-28T21:46:17.258Z",
"creator":{
"name":"Mckomo"
}
}
## Measurements Collection [/api/v1/stations/{station_id}/measurements]
+ Parameters
+ station_id (uuid) - ID of the Station that a new Measurement should be added to
### List All Station's Measurements [GET]
List Measurements associated to the Station with the given ID.
+ Response 200 (application/json)
[
{
"id":"d37e197a-1818-4dec-8dd4-568a0a681ea9",
"value":166.0,
"time":"2016-01-02T16:17:59.314Z",
"source":"http://monitoring.krakow.pios.gov.pl",
"norms":[
{
"id":"d5bbd3e4-a4a0-4a3d-8082-b5e5973875e8",
"value":200.0,
"level":"permissible",
"interval":"1 hour"
},
{
"id":"7f55e179-c28e-4b8d-96b4-83f86c323227",
"value":400.0,
"level":"alarming",
"interval":"1 hour"
},
{
"id":"8870aa65-5dd4-40e4-b8f4-5da27aa81d63",
"value":40.0,
"level":"permissible",
"interval":"1 year"
}
],
"subject":{
"id":"79f28303-696d-4fcc-9eab-005d869a8348",
"code":"NO2",
"name":"Dwutlenek azotu",
"unit":"µg/m\u003csup\u003e3\u003c/sup\u003e"
}
}
]
### Create a New Measurement [POST]
+ Request (application/json)
+ Headers
Authorization: Bearer AUTH_TOKEN
+ Body
{
"measurement":{
"value":626.0,
"time":"2016-01-02T16:17:59.314Z",
"source":"http://monitoring.krakow.pios.gov.pl",
"subject_id":"f70f05b9-76fa-4791-8ee4-463fd3f49956"
}
}
+ Response 201 (application/json)
+ Headers
Location: /api/v1/measurements/407f057a-788d-4e44-a278-391127193793
+ Body
{
"id":"407f057a-788d-4e44-a278-391127193793",
"value":626.0,
"time":"2016-01-02T16:17:59.314Z",
"source":"http://monitoring.krakow.pios.gov.pl",
"created_at":"2016-01-02T16:17:59.403Z",
"norms":[],
"subject":{
"id":"f70f05b9-76fa-4791-8ee4-463fd3f49956",
"code":"NO",
"name":"Tlenk azotu",
"unit":"µg/m\u003csup\u003e3\u003c/sup\u003e"
},
"creator":{
"name":"Mckomo"
}
}
+ Request (application/json)
+ Response 401 (application/json)
{
"message": "Unauthorized access error",
"exception": {},
"code": 401
}
+ Request (application/json)
+ Headers
Authorization: Bearer AUTH_TOKEN
+ Body
{
"measurement": {
"value":626.0
}
}
+ Response 422 (application/json)
{
"subject": [
"must exist",
"can't be blank"
],
"time": [
"can't be blank"
]
}
## Measurement [/api/v1/measurements/{measurement_id}]
+ Parameters
+ measurement_id (uuid) - ID of the Measurement
### View a Measurement Detail [GET]
+ Response 200 (application/json)
{
"id":"13f99447-dd96-4ee9-b218-191a9a1c1416",
"code":"PL0012A",
"name":"Kraków, Aleja Krasińskiego",
"latitude":50.057678,
"longitude":19.926189,
"created_at":"2015-12-28T21:46:17.258Z",
"updated_at":"2015-12-28T21:46:17.258Z",
"creator":{
"name":"Mckomo"
}
}
## Subjects Collection [/api/v1/subjects]
List all supported measurement subjects.
### List All Subjects [GET]
+ Response 200 (application/json)
[
{
"id":"79f28303-696d-4fcc-9eab-005d869a8348",
"code":"NO2",
"name":"Dwutlenek azotu",
"unit":"µg/m\u003csup\u003e3\u003c/sup\u003e",
"created_at":"2015-12-28T21:46:17.277Z",
"updated_at":"2015-12-28T21:46:17.277Z",
"norms":[
{
"id":"d5bbd3e4-a4a0-4a3d-8082-b5e5973875e8",
"value":200.0,
"interval":"1 hour",
"level":"permissible"
},
{
"id":"7f55e179-c28e-4b8d-96b4-83f86c323227",
"value":400.0,
"interval":"1 hour",
"level":"alarming"
},
{
"id":"8870aa65-5dd4-40e4-b8f4-5da27aa81d63",
"value":40.0,
"interval":"1 year",
"level":"permissible"
}
]
}
]
## Norms Collection [/api/v1/norms]
List all measurement norms.
### List All Norms [GET]
+ Response 200 (application/json)
[
{
"id":"d5bbd3e4-a4a0-4a3d-8082-b5e5973875e8",
"value":200.0,
"level":"permissible",
"interval":"1 hour",
"subject":{
"id":"79f28303-696d-4fcc-9eab-005d869a8348",
"code":"NO2",
"name":"Dwutlenek azotu",
"unit":"µg/m\u003csup\u003e3\u003c/sup\u003e"
}
}
]