Advertisement
Guest User

Untitled

a guest
May 7th, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. # API Documentation
  2. ## Miscellaneous
  3. ### `GET /api/status/`
  4. Returns empty dictionary if system is up.
  5.  
  6. #### Response statuses
  7. * `200`
  8. * `500`
  9.  
  10. #### Example
  11. ```
  12. GET /api/status/
  13.  
  14. 200 OK
  15. {}
  16. ```
  17.  
  18. ## User
  19. ### `GET /api/user/<id: int>/`
  20. Get information about a given user. Response contains:
  21. * username
  22. * first_name (optional)
  23. * last_name (optional)
  24. * email (optional)
  25.  
  26. #### Parameters
  27. * Required:
  28. * `id` (int) - An ID of a user.
  29.  
  30. #### Example
  31. ```
  32. GET /api/user/1337/
  33.  
  34. 200 OK
  35. {
  36. "username": "trainy",
  37. "first_name": "Trainy",
  38. "last_name": "McTrainFace",
  39. "email": "tmctf@trainmail.com"
  40. }
  41. ```
  42.  
  43. ### `POST /api/user/`
  44. Create a new user. Returns id of a new object.
  45.  
  46. #### Parameters
  47. * Required:
  48. * `username` (str) - User's username
  49. * `password` (str) - User's password
  50. * Optional:
  51. * `first_name` (str) - User's first name
  52. * `last_name` (str) - User's last name
  53. * `email` (str) - User's email
  54.  
  55. #### Example
  56. ```
  57. POST /api/user/
  58. username=trainy&password=ILikeTrains&first_name=Trainy&last_name=McTrainFace&email=tmctf@trainmail.com
  59.  
  60. 201 Created
  61. {
  62. "id": 1337
  63. }
  64. ```
  65.  
  66. ### `PATCH /api/user/<id: int>/`
  67. Update user's attributes. Returns all available user attributes.
  68.  
  69. #### Parameters
  70. * Required:
  71. * `id` (int) - User's ID
  72. * Optional:
  73. * `username` (str) - User's username
  74. * `first_name` (str) - User's first name
  75. * `last_name` (str) - User's last name
  76. * `email` (str) - User's email
  77.  
  78. #### Example
  79. ```
  80. PATCH /api/user/1337/
  81. email=tmctf@tmail.com
  82.  
  83. 200 OK
  84. {
  85. "username": "trainy",
  86. "first_name": "Trainy",
  87. "last_name": "McTrainFace",
  88. "email": "tmctf@tmail.com"
  89. }
  90. ```
  91.  
  92. ### `DELETE /api/user/<id: int>/`
  93. Delete user from database.
  94.  
  95. #### Parameters
  96. * Required
  97. * `id` (int) - User's ID
  98.  
  99. #### Example
  100. ```
  101. DELETE /api/user/1337/
  102. id=1337
  103.  
  104. 204 No content
  105. ```
  106.  
  107. ### `POST /api/user/<id: int>/password/`
  108. Change user's password. Returns `200 OK` on success, and validation errors on error.
  109.  
  110. #### Parameters
  111. * Required:
  112. * `id` (int) - User's ID
  113. * `old_password` (str) - Previous password
  114. * `new_password` (str) - New password
  115.  
  116. #### Example
  117. ```
  118. POST /api/user/1337/password/
  119. old_password=ILikeTrains&new_password=ILoveTrains
  120.  
  121. 200 OK
  122. {}
  123. ```
  124.  
  125. ## Training
  126. ### `GET /api/training/<id: int>/`
  127. Get information about a given training. Response contains:
  128. * begin_date
  129. * end_date
  130. * user_id
  131. * measurements - if present
  132.  
  133. #### Parameters
  134. * Required
  135. * `id` (int) - Training ID
  136.  
  137. #### Example
  138. ```
  139. GET /api/training/2137/
  140.  
  141. 200 OK
  142. {
  143. "begin_date": 1521051437,
  144. "end_date": 1521052437,
  145. "user_id": 1337,
  146. "measurements": {
  147. "heart_rate": [
  148. {"id": 1, "timestamp": 1521051437, "value": 120},
  149. {"id": 2, "timestamp": 1521051438, "value": 123},
  150. ...
  151. ],
  152. "speed": [
  153. {"id": 1, "timestamp": 1521051437, "value": 30.87},
  154. {"id": 2, "timestamp": 1521051438, "value": 32.3},
  155. ...
  156. ],
  157. ...
  158. }
  159. }
  160. ```
  161.  
  162. ### `POST /api/training/`
  163. Create a new training entry. Response contains training ID.
  164.  
  165. #### Parameters
  166. * Required
  167. * `begin_date` (timestamp) - Beginning of a training
  168. * `end_date` (timestamp) - Ending of a training
  169. * `user_id` (int) - User ID
  170.  
  171. #### Example
  172. ```
  173. POST /api/training/
  174. begin_date=1521051437&end_date=1521052437&user_id=1337,
  175.  
  176. 201 Created
  177. {'id': 2137}
  178. ```
  179.  
  180. ### `POST /api/training/batch/`
  181. Create a new training entry with all provided measurements. Response contains training ID.
  182.  
  183. #### Request body
  184. JSON similar to response in `GET /api/training/<id: int>/`.
  185.  
  186. #### Example
  187. ```
  188. POST /api/training/batch/
  189. {
  190. "begin_date": 1521051437,
  191. "end_date": 1521052437,
  192. "user_id": 1337,
  193. "measurements": {
  194. "heart_rate": [
  195. {"id": 1, "timestamp": 1521051437, "value": 120},
  196. {"id": 2, "timestamp": 1521051438, "value": 123},
  197. ...
  198. ],
  199. "speed": [
  200. {"id": 1, "timestamp": 1521051437, "value": 30.87},
  201. {"id": 2, "timestamp": 1521051438, "value": 32.3},
  202. ...
  203. ],
  204. ...
  205. }
  206. }
  207.  
  208. 201 Created
  209. {'id': 2137}
  210. ```
  211.  
  212. ### `DELETE /api/training/<id: int>/`
  213. Delete a given training.
  214.  
  215. #### Parameters
  216. * Required
  217. * `id` (int) - Training ID
  218.  
  219. #### Example
  220. ```
  221. DELETE /api/training/2137/
  222.  
  223. 204 No Content
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement