Have you installed the Well-Read Service in your development system? Make sure you have all the prerequisites to run the service in your system before you continue.
The Well-Read Service has an extensive collection of books in its database with different fantasy subgenres. However, the database occasionally needs to be updated to include newly published books or recommended novels.
This tutorial teaches you how to add a book
resource to the collection with properties that match a persona
resource’s criteria.
The tutorial takes approximately 20 minutes to complete.
For this tutorial, you’ll add a book
resource that matches the Adrenaline Junkie persona.
You can view the resource object for the Adrenaline Junkie persona below:
{
"name": "Adrenaline Junkie",
"description": "Likes high-fantasy books in the realm of science fiction or medieval times that often includes an anti-hero that must save their world.",
"subgenres_explored": ["science-fiction", "epic", "sword-and-stone", "futuristic"],
"typical_pace": ["fast"],
"related_tags":["dark","world-building", "emotional","adventurous", "war"],
"id": 4
}
Using the POST
method, you’ll add the book A Memory Called Empire by Arkady Martine to the database, which shares the science-fiction
subgenre and the fast
reading pace preferences of the Adrenaline Junkie persona.
Start the service by running this command in your preferred command-line tool:
cd <directory of the database file location>
json-server well-read-db.json
{base_url}/books
Content-Type: application/json
{
"title": "A Memory Called Empire",
"author": "Arkady Martine",
"page_count": 462,
"subgenre":"science-fiction",
"pace": "fast",
"tags":["world-building", "politics", "mystery", "space opera"],
"is_series":"true"
}
The request body must include all the properties listed in the book
resource page. It should also include the key-value pairs: subgenre: science-fiction
, pace: fast
to match the Adrenaline Junkie persona properties.
The response body should return the new book
resource for A Memory Called Empire, including a unique ID for the book.
{
"title": "A Memory Called Empire",
"author": "Arkady Martine",
"page_count": 462,
"subgenre": "science-fiction",
"pace": "fast",
"tags": [
"world-building",
"politics",
"mystery",
"space opera"
],
"is_series": "true",
"id": 6
}
Now that you’ve added a new book
resource to the collection, you can try to get it as a book recommendation by reviewing the steps in the quickstart tutorial.
You can also find all the books with the science-fiction
subgenre by following the Find books by subgenre tutorial.