This repository contains source code of the simple API server which allows retrieving, adding, modifying and deleting entries from MySQL database table.
We're assumming that you're using CentOS and Python 2, so to run this project you have to complete following steps:
sudo yum install gcc python-devel
git clone http://192.168.103.236:3000/Lv-335.DevOps/API_Server_Demo.git
sudo pip install -r requirements.txt
5. Create database, table or even fill table with some data using appropriate scripts in project`s sql folder.
example:
{ "db":{
"host":"ip address",
"user":"username",
"passwd":"password",
"database":"name"
}
}
python API.py
Returns json data about all trainees
-
URL
/api/v1/trainees
-
Method:
GET
-
Successful Response:
-
Code: 200
Content:
{ id:1, Firstname : "Name", Lastname : "Name", Age : "20" }
-
Error Response:
-
Code: 404 NOT FOUND
Content:
{ Error : "Table is empty" }
-
Returns json data about trainee with the specified id
-
URL
/api/v1/trainees/<id>
-
Method:
GET
-
URL Params
Required:
id=[integer]
-
Successful Response:
-
Code: 200
Content:
{ id:1, Firstname : "Name", Lastname : "Test", Age : "20" }
-
-
Error Response:
-
Code: 404 NOT FOUND
Content:
{ Error : "Trainee with the specified id <id> does not exist" }
-
Deletes trainee with the specified id
-
URL
/api/v1/trainees/<id>
-
Method:
DELETE
-
URL Params
Required:
id=[integer]
-
Success Response:
-
Code: 200
Content:
"1 record deleted"
-
Error Response:
-
Code: 404 NOT FOUND
Content:
{ Error : "Trainee with the specified id <id> does not exist" }
-
Creates new trainee
-
URL
/api/v1/trainees
-
Method:
POST
-
Data Params:
Required:
Firstname=[string]
Lastname=[string]
Age=[integer]
-
Success Response:
-
Code: 201
Content:
"Created"
-
-
Error Response:
-
Code: 400 BAD REQUEST
Content:
{ Error : "Some values of parameters are empty" }
-
Updates one or more parameters of trainee with specified id
-
URL
/api/v1/trainees/<id>
-
Method:
PUT
-
URL Params
Required:
id=[integer]
-
Data Params:
Required (one or more):
Firstname=[string]
Lastname=[string]
Age=[integer]
-
Success Response:
- Code: 201
Content:
"1 record affected"
-
Error Response:
-
Code: 400 BAD REQUEST
Content:
{ Error : "Values of parameters are empty" }
OR
-
Code: 404 NOT FOUND
Content:
{ Error : "Trainee with the specified id <id> does not exist" }
-
Returns json with basic information about all drives
-
URL
/api/v1/disk
-
Method:
GET
-
Successful Response:
- Code: 200
Content:
[
{
"used": "1G",
"total": "16G",
"percent": 9.2,
"Drive": "/",
"free": "15G"
},
{
"used": "171M",
"total": "1014M",
"percent": 16.9,
"Drive": "/boot",
"free": "842M"
}
]