Audio-server-api
is a Flask web API that simulates the behavior of an audio file
server while using a SQL database.
The app is deployed on Heroku and can be tested using Postman or any other API testing tool. If you are testing using Postman, please feel free to download the Audio Server API Test.postman_collection.json
[Exported as Collection v2.1] file and import it in Postman.
App url: https://audioapi.herokuapp.com
To setup and use the api on your local device, follow the instructions:
To setup the environment with the packages needed to run the app, first create a virtual environment and then install the packages from the requirements.txt
>> conda create --name myenv python=3.8
>> pip install -r requirements.txt
The API supports 3 audio file types (audioFileType
), they are:
song
podcast
audiobook
id
: Unique identifier set automaticallyname
: Name of the song, passed in request body – (mandatory, string, cannot be larger than 100 characters)duration
: Duration in number of seconds, passed in request body – (mandatory, integer, positive)uploaded_time
Uploaded time, set automatically to the time when a record gets saved in the database
id
: Unique identifier set automaticallyname
: Name of the song, passed in request body – (mandatory, string, cannot be larger than 100 characters)duration
: Duration in number of seconds, passed in request body – (mandatory, integer, positive)host
: Host of the podcast, passed in request body – (mandatory, string, cannot be larger than 100 characters)participants
: Participants, passed in request body as a list of strings (optional, list of strings, each string cannot be larger than 100 characters, maximum of 10 participants possible)uploaded_time
Uploaded time, set automatically to the time when a record gets saved in the database
id
: Unique identifier set automaticallyname
: Name of the song, passed in request body – (mandatory, string, cannot be larger than 100 characters)duration
: Duration in number of seconds, passed in request body – (mandatory, integer, positive)author
: Author of the song, passed in request body – (mandatory, string, cannot be larger than 100 characters)narrator
: Narrator of the song, passed in request body – (mandatory, string, cannot be larger than 100 characters)uploaded_time
Uploaded time, set automatically to the time when a record gets saved in the database
The api mainly have 3 endpoints, they are:
{{url}}/{{audioFileType}}
-> Get list of all records available{{url}}/{{audioFileType}}/{{audioFileID}}
-> Get, update or delete a specific file{{url}}/
-> create a new file
Endpoint: {{url}}/
Request Body:
{
"audioFileType": "song",
"audioFileMetadata": {
"name": "Test",
"duration": 360
}
}
Resonse status code: 200 Sample Response data if song is successfully created:
{
"id": 30,
"name": "Test",
"duration": 360,
"uploaded_time": "2021-03-21T13:15:38.612827"
}
if there was a problem in creating a record, 400 status code will be returned.
- name, duration, host is mandatory fields
Endpoint: {{url}}/
Request Body:
{
"audioFileType": "podcast",
"audioFileMetadata": {
"name": "Test podcast",
"duration": 360,
"host": "Test host",
"participants": [
"participant 1",
"participant 2",
"participant 3"
]
}
}
Resonse status code: 200 Sample Response data if song is successfully created:
{
"id": 31,
"name": "Test podcast",
"duration": 360,
"host": "Test host",
"participants": [
"participant 2",
"participant 1",
"participant 3"
],
"uploaded_time": "2021-03-21T13:22:05.923891"
}
if there was a problem in creating a record, 400 status code will be returned.
- name, duration, host is mandatory fields
- participants list is optional
- participants cannot have more than 10 participants
If any of these conditions are not satisfied in the request body, record will not be created and 400 status code will be returned along with the specific validation error.
Endpoint: {{url}}/
Request Body:
{
"audioFileType": "audiobook",
"audioFileMetadata": {
"name": "Test audiobook",
"duration": 3600,
"author": "Test author",
"narrator": "Test narrator"
}
}
Resonse status code: 200 Sample Response data if song is successfully created:
{
"id": 32,
"name": "Test audiobook",
"duration": 3600,
"author": "Test author",
"narrator": "Test narrator",
"uploaded_time": "2021-03-21T13:27:31.020855"
}
if there was a problem in creating a record, 400 status code will be returned.
- name, duration, author, narrator are mandatory fields
If any of these conditions are not satisfied in the request body, record will not be created and 400 status code will be returned along with the specific validation error.
Endpoint: {{url}}/{{audioFileType}}/{{audioFileID}}
Example GET request: {{url}}/song/30
Example Response (200 OK):
{
"id": 30,
"name": "Test",
"duration": 360,
"uploaded_time": "2021-03-21T13:15:38.612827"
}
Example DELETE request: {{url}}/song/30
Example Response (200 OK):
{
"Message": "Successfully deleted record"
}
Example request: {{url}}/song/3334
Example GET Response (400 BAD REQUEST):
{
"Message": "File not found"
}
Endpoint: {{url}}/{{audioFileType}}
Example GET Request: {{url}}/song
Example Response (200 OK):
[
{
"id": 22,
"name": "Test 1",
"duration": 250,
"uploaded_time": "2021-03-19T07:49:19.748314"
},
{
"id": 24,
"name": "Test 2",
"duration": 233,
"uploaded_time": "2021-03-19T13:36:19.857718"
},
{
"id": 27,
"name": "Test 3",
"duration": 233,
"uploaded_time": "2021-03-21T07:44:13.501365"
}
]
For updating a record, we need to specify the file type and file id in the request url, just like the GET or DELETE method, but we also need to give the fields that we need to change with the updated values. It is to be noted that, while updating a existing record, it is not required to have all the required fields (that must be in the request body when creating a file)
Endpoint: {{url}}/
Example request body to update the podcast Test podcast
created above:
{
"duration": 500,
"participants": [
"Participant 4"
]
}
Request returns the updated file data in the response body: Response (200 OK):
{
"id": 31,
"name": "Test podcast",
"duration": 500,
"host": "Test host",
"participants": [
"Participant 4"
],
"uploaded_time": "2021-03-21T13:22:05.923891"
}