API — Book Operations
Each book must consists of multiple parts of information. Here’s the rules:
- A book must have a book genre at all times
- A book can only have one book genre at any given time
- A book must have at least one author
- A book can have multiple authors
Based on this let’s dive into all book related endpoints and how to use them.
Create an Author
This endpoint provides functionality to create a new author in the system.
-
Perform a
POST
request: -
This should provide a response like:
-
Take note of the
authorID
field and copy that value, the subsequent sections will make use of this value as a path parameter.
Get all Authors
This endpoint provides functionality to retrieve all authors found in the system. If there are no
authors found an empty array will be returned: [ ]
-
Perform a
GET
request: -
This should provide a response like:
-
This response includes the author we just created.
Get Author by AuthorID
This endpoint provides functionality to retrieve a single author by making use of the authorID
value. This value is passed along to the back-end application by the means of a path parameter
value and serves as the lookup key.
-
Perform a
GET
request: -
This should provide a response like:
-
This response correlates with the
authorID
supplied in the path parameter.
Update Author by AuthorID
This endpoint provides functionality to update an existing author by making use of the
authorID
value. This value is passed along to the back-end application by the means of a path
parameter value and serves as the lookup key.
-
Perform a
PUT
request: -
There is no response body, and the HTTP status code is
HTTP 204 No Content
-
You can run the Get Author by AuthorID request again to see the difference. The response will show the updated
additionalName
value which has been added, the new value beingJohn
.
Create Book with Authors
In order to create a new book, at least one authorID
must be included in the request since a
book must always have at least one author associated with it. You will also need to include a
valid bookGenreID
since a book must always have a book genre associated with it.
This endpoint provides functionality to create a new book. As can be seen in the request body
below, functionality allows to include multiple authorIDs
so you don’t have to add authors
one-by-one.
-
Perform a
POST
request: -
This should provide a response like:
Get Books with Links
A book has certain “links” or associations. These links are: a book genre item and author items.
This endpoint provides functionality to retrieve all the books in the system with their
associated links. If there are no books found then an empty array will be returned: [ ]
-
Perform a
GET
request: -
This should provide a response like:
-
This response will provide all books in the system with all related information. This includes all author information as well as book genre information.
Get all Books
This endpoint will retrieve all the book items found in the system. Note that this endpoint does not include the associated links for each book, but rather only contains the “core” details of each book item.
If there are no books found in the system, an empty array will be returned: [ ]
-
Perform a
GET
request: -
This should provide a response like:
-
This response will return all books but only include the book’s core information. The book genre and author information is excluded.
Get Book by BookID
This endpoint provides functionality to retrieve a specific book by making use of the bookID
value as the lookup key. The bookID
value is passed along to the back-end application by the
means of a path parameter variable.
-
Perform a
GET
request: -
This should provide a response like:
-
This response will return all books but only include the book’s core information. The book genre and author information is excluded.
Get Book with Links by BookID
This endpoint provides functionality to retrieve a specific book’s details along with its
associated links by making use of the bookID
value as the lookup key. The bookID
value is
passed along to the back-end application by the means of a path parameter variable.
-
Perform a
GET
request: -
This should provide a response like:
-
This response returns a single book item based on the
bookID
supplied with all links which includes the author information as well as the book genre information.
Get Authors with Books
This endpoint provides functionality to retrieve all authors in the system along with all of their associated books. The book item details will only include the book’s core details.
-
Perform a
GET
request: -
This should provide a response like:
-
This response returns all the books linked to all authors in the system.
Get Author with Books by AuthorID
This endpoint provides functionality to retrieve all the books associated with a specific author.
The authorID
value is used as the lookup key. The authorID
value is passed along to the
back-end application by the means of a path parameter variable.
-
Perform a
GET
request: -
This should provide a response like:
-
This response returns all the books for a single author based on the
authorID
value in the path parameter.
Update Book by BookID
This endpoint provides functionality to update an existing book by making use of the bookID
value. The bookID
value is used as the lookup key and passed along to the back-end application
by the means of a path parameter variable.
Note the reduced allowable property values in the request body. Not all properties or a book’s core details are updatable.
-
Perform a
PUT
request: -
There is no response body, and the HTTP status code is
HTTP 204 No Content
-
You can run the Get Book by BookID request again to see the difference. The response will show the updated book information as reflected in the request body above.
Update Book Genre
This endpoint provides functionality to update a specific book’s genre association. There is no request body needed as the values will be picked up from the request URI.
The bookID
and bookGenreID
values are used as lookup and replacement values. They are passed
along to the back-end application by the means of path parameter variables.
-
Perform a
PUT
request: -
There is no response body, and the HTTP status code is
HTTP 204 No Content
-
You can run the Get Book with Links by BookID request again to see the difference. The response will show the updated book information.
Add Author to Book
Currently, only one author exists (the one created earlier). Let’s create another one and add the newly created one to the book as well. This means this book will have two authors after the request is completed.
This endpoint provides functionality to add a single author to an existing book item. This is
done by making use of the bookID
and authorID
values as both lookup and addition values
respectively. They are passed along to the back-end application by the means of path parameter
variables.
-
Perform a
POST
request to create another author: -
This should provide a response like:
-
Take note of the
authorID
field and copy that value, the subsequent steps will make use of this value as a path parameter. -
Perform a
PUT
request to add an additional author to the book: -
There is no response body, and the HTTP status code is
HTTP 204 No Content
-
Run the Get Book with Links by BookID request again to see the difference
-
You can see from the response above that the book contains all the updated information, including the genre change, and additional author which we added.
Remove Author from Book
This endpoint provides functionality to remove an author from an existing book. Keep in mind that you will note be able to remove an author from any book if that author is the only author associated with that specific book. A book must have at least one author associated with it.
The bookID
value is used as the lookup value. The authorID
value is used as the value to be
removed from the association. They are passed along to the back-end application by the means of
path parameter variables.
-
Perform a
DELETE
request: -
There is no response body, and the HTTP status code is
HTTP 204 No Content
-
Run the Get Book with Links by BookID request again to see the difference
-
As can be seen in the response above, the author has been removed.
Summary
Endpoints covered in this guide are as follows:
POST /authors
- Create a new author
GET /authors
- Retrieve all authors in the system
GET /authors/<authorID>
- Get a specific author by making use of the
authorID
value
- Get a specific author by making use of the
PUT /authors/<authorID>
- Update a specific author by making use of the
authorID
value
- Update a specific author by making use of the
POST /books
- Create a book with Authors
GET /books/links
- Retrieve all books in the system along with their associated links
GET /books
- Retrieve all books in the system with only the book’s core values
GET /books/<bookID>
- Get a specific book by making use of the
bookID
value
- Get a specific book by making use of the
GET /books/<bookID>/links
- Get a specific book along with its associated links by making use of the
bookID
value
- Get a specific book along with its associated links by making use of the
GET /authors/books
- Retrieve all authors in the system along with their associated books
GET /authors/<authorID>/books
- Get a single author and its associated books by making use of the
authorID
value
- Get a single author and its associated books by making use of the
PUT /books/<bookID>
- Update a specific book by making use of the
bookID
value
- Update a specific book by making use of the
PUT /books/<bookID>/genres/<bookGenreID>
- Update a specific book’s genre by making use of both the
bookID
andbookGenreID
values
- Update a specific book’s genre by making use of both the
PUT /books/<bookID>/authors/<authorID>
- Add an author to an existing book by making use of both the
bookID
and theauthorID
values
- Add an author to an existing book by making use of both the
DELETE /books/<bookID>/authors/<authorID>
- Remove an author from an existing book by making use of both the
bookID
and theauthorID
values
- Remove an author from an existing book by making use of both the