This project is built on Python Language and Django Rest Framework as a way to provide an API in order to save data for authors and their respective books.
To run this project it's necessary to have python >= 3.6 installed and follow the steps below:
$ sudo apt install virtualenv
In order to create the virtual environment, it's necessary to run:
$ virtualenv --python=python3.6 .my_env
and then, activate it:
$ source .my_env/bin/activate
Once the virtual environment is activated, it's necessary to run the requirements:
$ pip install -r requirements.txt
It's necessary to create a .env file at the root directory with the following entry:
SECRET_KEY=AnythingYouWant
$ python manage.py makemigrations
$ python manage.py migrate
Now it's possible to start the server by running:
$ python manage.py runserver
To run the tests:
$ python manage.py test
This application is deployed on
https://library-testapi.herokuapp.com/
In order to get the list of authors, it's necessary to do a GET action on:
https://library-testapi.herokuapp.com/v1/authors/
Output:
[
{
"id": 1,
"name": "Luciano Ramalho"
},
{
"id": 2,
"name": "Osvaldo Santana Neto"
},
{
"id": 3,
"name": "David Beazley"
},
{
"id": 4,
"name": "Chetan Giridhar"
},
{
"id": 5,
"name": "Brian K. Jones"
},
{
"id": 6,
"name": "J.K Rowling"
},
{
"id": 7,
"name": "Luciano Ramalho"
},
{
"id": 8,
"name": "Osvaldo Santana Neto"
},
{
"id": 9,
"name": "David Beazley"
},
{
"id": 10,
"name": "Chetan Giridhar"
},
{
"id": 11,
"name": "Brian K. Jones"
},
{
"id": 12,
"name": "J.K Rowling"
},
{
"id": 13,
"name": "Aurelio Marinho Jargas"
},
{
"id": 14,
"name": "Danilo Gazzoli"
},
{
"id": 15,
"name": "Danilo Gazzoli Resende"
}
]
Status: 200 OK
If you want to retrieve only one author:
https://library-testapi.herokuapp.com/v1/authors/{Author id}
Example:
https://library-testapi.herokuapp.com/v1/authors/1
Output:
{
"id": 1,
"name": "Luciano Ramalho"
}
Status: 200 OK
if you wanna add an author, it's necessary a POST action on:
https://library-testapi.herokuapp.com/v1/authors/
with the Json content:
{"name" : "Agatha Cristie"}
Output:
{
"id": 16,
"name": "Agatha Cristie"
}
Status: 201 Created
If you want to get the list of books, do a GET action on:
https://library-testapi.herokuapp.com/v1/books/
Output:
[
{
"id": 2,
"authors": [
{
"id": 2,
"name": "Osvaldo Santana Neto"
},
{
"id": 3,
"name": "David Beazley"
},
{
"id": 7,
"name": "Luciano Ramalho"
}
],
"name": "Expressões regulares",
"edition": 2,
"publication_year": 2019
},
{
"id": 3,
"authors": [
{
"id": 1,
"name": "Luciano Ramalho"
},
{
"id": 2,
"name": "Osvaldo Santana Neto"
}
],
"name": "TDD com python",
"edition": 2,
"publication_year": 2019
},
{
"id": 4,
"authors": [
{
"id": 1,
"name": "Luciano Ramalho"
},
{
"id": 2,
"name": "Osvaldo Santana Neto"
}
],
"name": "TDD com python 3",
"edition": 2,
"publication_year": 2019
}
]
Status: 200 OK
In order to retrieve only one book:
https://library-testapi.herokuapp.com/v1/books/{book id}
Example:
https://library-testapi.herokuapp.com/v1/books/3
Output:
{
"id": 3,
"authors": [
{
"id": 1,
"name": "Luciano Ramalho"
},
{
"id": 2,
"name": "Osvaldo Santana Neto"
}
],
"name": "TDD com python",
"edition": 2,
"publication_year": 2019
}
Status: 200 OK
In order to add a book, it's necessary to do a POST action on:
https://library-testapi.herokuapp.com/v1/books/
with the Json Content:
{
"name": "Mistério no Caribe",
"edition": "1",
"publication_year": 1964,
"authors": [16]
}
Output:
{
"id": 5,
"name": "Mistério no Caribe",
"edition": 1,
"publication_year": 1964,
"authors": [
16
]
}
Status: 201 Created
If it's necessary to update a any field, then send a PATH action to:
https://library-testapi.herokuapp.com/v1/books/{Book id}/
Example:
https://library-testapi.herokuapp.com/v1/books/5/
with the Json content that must be updated:
{
"edition": "2"
}
Output:
{
"id": 5,
"name": "Mistério no Caribe",
"edition": 2,
"publication_year": 1964,
"authors": [
16
]
}
Status: 200 OK
And, finally, if it's necessary to be delete, send a DELETE action to:
https://library-testapi.herokuapp.com/v1/books/{Book id}/
Example:
https://library-testapi.herokuapp.com/v1/books/5/
Status: 204: no Content
This application was built on vim and Pycharm 2020.1 (Community Edition), running Ubuntu Linux:
Linux Inspiron 5.3.0-46-generic #38~18.04.1-Ubuntu SMP Tue Mar 31 04:17:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux