This is a simple backend engineering case study for my Albert job application python challenge. It supplies endpoints that allow users to search for books using the Open Library API in order to get details about a specific book.
Additionally, it also supplies endpoints for a global “wish list” to which we can add and remove books we like, and retrieve a detailed listing of books that are in the wish list.
- Download the repository locally
- Navigate to the directory in a shell, and create a virtualenv using Python3 as its base, example
virtualenv -p python3 venv
- To enter the virtualenv, run
source venv/bin/activate
- Install necessary packages into the virtualenv by running
pip install -r requirements.txt
- To create the wishlist model, run
python manage.py migrate
- If you'd like to be able to use the admin panel, run
python manage.py createsuperuser
- Start the server by running
python manage.py runserver
- Use your client of choice (eg Postman) to interact with the endpoints at http://127.0.0.1:8000/
The endpoints fall into two categories:
/openlib
- Open Library calls/openlib/search
- GET - searches for books that match parametertitle
- eg
http://127.0.0.1:8000/openlib/search?title=Lord+of+the+Rings
- eg
/openlib/details
- GET - gets detailed information about book matching parameterkey
- eg
http://127.0.0.1:8000/openlib/detail?key=/books/OL7668717M
- eg
/wishlist
- wish list functionality/wishlist/add
- POST - add book to wish list specified by parameterkey
iff it exists in the Open Library and is not already in the wish list- eg POST body
{ "key": "/b/OL26793280M" }
- NOTE: this function auto-expands keys starting with
/b/
to start with/books/
- eg POST body
/wishlist/remove
- POST - remove book from wish list specified by parameterkey
- eg POST body
{ "key": "/b/OL26793280M" }
- eg POST body
/wishlist/list_all
- GET - no parameters - return a list of all books in the wish list, with detailed information supplied by Open Library- eg
http://127.0.0.1:8000/wishlist/list_all
- The response body includes a date->book_list section, which is a dictionary containing one entry
per book key, and each entry containing the details for that book, stored in a dictionary.
- If an invalid book key is somehow added to the wish list, say via admin, then the value for that book in the response body is the string "no details found" instead of the details dictionary.
- eg
The endpoints all return a JSEND structured-result. One slight modification is that the "fail" responses may include a message, for extra help debugging the failure.
The endpoints also return some http status codes for compatibility, and hopefully not to be confusing alongside the JSEND response body.
http://127.0.0.1:8000/openlib/search?title=Lord+of+the+Rings
{
"status": "success",
"data": {
"openlib_result": {
"status": "ok",
"result": [
"/books/OL26793280M",
"/books/OL3328599M",
"/books/OL8773280M",
"/books/OL8773281M",
<...>
}
http://127.0.0.1:8000/wishlist/add + { "key": "/b/OL26793280M" }
{
"status": "fail",
"message": "book already exists in wish list: /books/OL26793280M"
}
As mentioned above, a typical admin panel can be found at http://127.0.0.1:8000/admin/.
You can tweak the wish list of Books manually here. Note that when you add a book here, there is no verification
of the validity of a key_text
value for a Book, as there is when you call the /wishlist/add
endpoint.
- Currently there is no limit to the number of books that can be added to a wish list. Accordingly, calls to the
/wishlist/list_all
endpoint could become slow due to a single call being made to Open Library for each book. - Attempts have been made to deal with real-world scenarios like timeouts from third-party API’s, but edge cases likely remain.