Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # API Documentation
- ## Miscellaneous
- ### `GET /api/status/`
- Returns empty dictionary if system is up.
- #### Response statuses
- * `200`
- * `500`
- #### Example
- ```
- GET /api/status/
- 200 OK
- {}
- ```
- ## User
- ### `GET /api/user/<id: int>/`
- Get information about a given user. Response contains:
- * username
- * first_name (optional)
- * last_name (optional)
- * email (optional)
- #### Parameters
- * Required:
- * `id` (int) - An ID of a user.
- #### Example
- ```
- GET /api/user/1337/
- 200 OK
- {
- "username": "trainy",
- "first_name": "Trainy",
- "last_name": "McTrainFace",
- "email": "tmctf@trainmail.com"
- }
- ```
- ### `POST /api/user/`
- Create a new user. Returns id of a new object.
- #### Parameters
- * Required:
- * `username` (str) - User's username
- * `password` (str) - User's password
- * Optional:
- * `first_name` (str) - User's first name
- * `last_name` (str) - User's last name
- * `email` (str) - User's email
- #### Example
- ```
- POST /api/user/
- username=trainy&password=ILikeTrains&first_name=Trainy&last_name=McTrainFace&email=tmctf@trainmail.com
- 201 Created
- {
- "id": 1337
- }
- ```
- ### `PATCH /api/user/<id: int>/`
- Update user's attributes. Returns all available user attributes.
- #### Parameters
- * Required:
- * `id` (int) - User's ID
- * Optional:
- * `username` (str) - User's username
- * `first_name` (str) - User's first name
- * `last_name` (str) - User's last name
- * `email` (str) - User's email
- #### Example
- ```
- PATCH /api/user/1337/
- email=tmctf@tmail.com
- 200 OK
- {
- "username": "trainy",
- "first_name": "Trainy",
- "last_name": "McTrainFace",
- "email": "tmctf@tmail.com"
- }
- ```
- ### `DELETE /api/user/<id: int>/`
- Delete user from database.
- #### Parameters
- * Required
- * `id` (int) - User's ID
- #### Example
- ```
- DELETE /api/user/1337/
- id=1337
- 204 No content
- ```
- ### `POST /api/user/<id: int>/password/`
- Change user's password. Returns `200 OK` on success, and validation errors on error.
- #### Parameters
- * Required:
- * `id` (int) - User's ID
- * `old_password` (str) - Previous password
- * `new_password` (str) - New password
- #### Example
- ```
- POST /api/user/1337/password/
- old_password=ILikeTrains&new_password=ILoveTrains
- 200 OK
- {}
- ```
- ## Training
- ### `GET /api/training/<id: int>/`
- Get information about a given training. Response contains:
- * begin_date
- * end_date
- * user_id
- * measurements - if present
- #### Parameters
- * Required
- * `id` (int) - Training ID
- #### Example
- ```
- GET /api/training/2137/
- 200 OK
- {
- "begin_date": 1521051437,
- "end_date": 1521052437,
- "user_id": 1337,
- "measurements": {
- "heart_rate": [
- {"id": 1, "timestamp": 1521051437, "value": 120},
- {"id": 2, "timestamp": 1521051438, "value": 123},
- ...
- ],
- "speed": [
- {"id": 1, "timestamp": 1521051437, "value": 30.87},
- {"id": 2, "timestamp": 1521051438, "value": 32.3},
- ...
- ],
- ...
- }
- }
- ```
- ### `POST /api/training/`
- Create a new training entry. Response contains training ID.
- #### Parameters
- * Required
- * `begin_date` (timestamp) - Beginning of a training
- * `end_date` (timestamp) - Ending of a training
- * `user_id` (int) - User ID
- #### Example
- ```
- POST /api/training/
- begin_date=1521051437&end_date=1521052437&user_id=1337,
- 201 Created
- {'id': 2137}
- ```
- ### `POST /api/training/batch/`
- Create a new training entry with all provided measurements. Response contains training ID.
- #### Request body
- JSON similar to response in `GET /api/training/<id: int>/`.
- #### Example
- ```
- POST /api/training/batch/
- {
- "begin_date": 1521051437,
- "end_date": 1521052437,
- "user_id": 1337,
- "measurements": {
- "heart_rate": [
- {"id": 1, "timestamp": 1521051437, "value": 120},
- {"id": 2, "timestamp": 1521051438, "value": 123},
- ...
- ],
- "speed": [
- {"id": 1, "timestamp": 1521051437, "value": 30.87},
- {"id": 2, "timestamp": 1521051438, "value": 32.3},
- ...
- ],
- ...
- }
- }
- 201 Created
- {'id': 2137}
- ```
- ### `DELETE /api/training/<id: int>/`
- Delete a given training.
- #### Parameters
- * Required
- * `id` (int) - Training ID
- #### Example
- ```
- DELETE /api/training/2137/
- 204 No Content
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement