Back-end Application developed in Python using Flask, SQLAlchemy with a RESTful API, Unit Tests and API tests for Udacity Course in API Development and Documentation
This is a simple Back-End application to store Books.
To run API tests just run test_flaskr.py file with python.
Example: python3 test_flaskr.py
To start the application clone the Github repository. Open the project directory and set up Flask environment in a terminal execute the following commands:
export FLASK_ENV = development
export FLASK_APP = flaskr
flask run
Make sure you have flask installed to be able to host this project locally. After typing this into terminal you should be running the flask app on port http://127.0.0.1:5000/ and see a message in the terminal:
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 473-405-251
{
"success": False,
"error": 400,
"message": "Bad request!"
}
The API will retern three error types when requests fail:
* 404 Resource Not Found
* 422 Not Processable
- Returns a list of book objects, value of success and a total number of books
- Results are paginated in groups of 8. Include a request argument to choose page number, starting from 1.
- Sample : In terminal with curl installe type:
curl http://127.0.0.1:5000/books
- Sample Response :
{ "books": [ { "author": "Petar Deunov", "id": 1, "rating": 10, "title": "Paneurythmy" }, { "author": "Petar Deunov", "id": 3, "rating": 10, "title": "The two ways" }, { "author": "Nikolay Doinov", "id": 5, "rating": 10, "title": "Astrology" } ], "success": true, "total": 3 }
- Creates a new book using the submitted title, author and rating. Return the id of the created book, success value, total vooks and book list based on current page number to update.
- Example:
curl http://127.0.0.1:5000 -X POST -H "Content-Type: application/json" -d '{"title":"Masons", "author":"Jean Palu", "rating":"5"}'
- Example response:
{ "books": [ { "author": "Petar Deunov", "id": 1, "rating": 10, "title": "Paneurythmy" }, { "author": "Petar Deunov", "id": 3, "rating": 10, "title": "The two ways" }, { "author": "Nikolay Doinov", "id": 5, "rating": 10, "title": "Astrology" }, { "author": "Jean Palu", "id": 6, "rating": 5, "title": "Masons" } ], "created": 6, "success": true, "total_books": 4 }
- Deletes a selected book id. Returns books, success value, total length and deleted id.
- Example:
curl -X DELETE http://127.0.0.1:5000/books/6
- Example Response:
{ "books": [ { "author": "Petar Deunov", "id": 1, "rating": 10, "title": "Paneurythmy" }, { "author": "Petar Deunov", "id": 3, "rating": 10, "title": "The two ways" }, { "author": "Nikolay Doinov", "id": 5, "rating": 10, "title": "Astrology" } ], "deleted": 6, "success": true, "total_books": 3 }
- If provided, updates rating of the specific book_id. Return success value and id of the updated Book.
- Example:
curl -X PATCH http://127.0.0.1:5000/books/5 -H "Content-Type: application/json" -d '{"rating":"11"}'
- Example Response:
{ "id": 5, "success": true }