-
Notifications
You must be signed in to change notification settings - Fork 4
library running
Once everything is ready, build the project:
mvn install
and run it:
mvn -pl library-service exec:java
Getting a single book:
» curl -s -g http://localhost:8888/books/123
No book with id 123
» curl -s -g http://localhost:8888/books/1 | jq
{
"author": {
"firstName": "Allan",
"lastName": "Poe"
},
"text": "MANY years ago, I contracted an intimacy with a Mr. William Legrand. He was of an ancient Huguenot f"
}
Book with id 123
doesn't exist. Book with id 1
exists, and we got
it back with the default output. If we only want to get text back we
can do just that:
» curl -s -g "http://localhost:8888/books/1/text"
"MANY years ago, I contracted an intimacy with a Mr. William Legrand. He was of an ancient Huguenot f"
We only got 100 characters back because that's the default specified for
count
parameter.
Here's what happens if we ask for a non-existent field
» curl -s -g "http://localhost:8888/books/1(id)"
Unsupported field 'id', supported fields: (author,text,title)
/books/1(id)
^^
OK, id
field is not supported, lets ask for something which is
curl -s -g "http://localhost:8888/books[1,2](title,author)" | jq
[
{
"K": 1,
"V": {
"title": "The Gold Bug",
"author": {
"firstName": "Allan",
"lastName": "Poe"
}
}
},
{
"K": 2,
"V": {
"title": "A Study In Scarlet",
"author": {
"firstName": "Arthur",
"lastName": "Doyle"
}
}
}
]
author
still receives default projection. We could also specify the one
we want explicitly:
curl -s -g "http://localhost:8888/books[1,2](title,author:record(firstName,middleName,lastName))" | jq
[
{
"K": 1,
"V": {
"title": "The Gold Bug",
"author": {
"firstName": "Allan",
"lastName": "Poe"
}
}
},
{
"K": 2,
"V": {
"title": "A Study In Scarlet",
"author": {
"firstName": "Arthur",
"middleName": "Conan",
"lastName": "Doyle"
}
}
}
]
We can ask for both id
and record
tags at the same time. And for
some non-existent entry in addition.
curl -s -g "http://localhost:8888/books[1,2,5](title,author:(id,record(firstName,middleName,lastName)))" | jq
[
{
"K": 1,
"V": {
"title": "The Gold Bug",
"author": {
"id": 1,
"record": {
"firstName": "Allan",
"lastName": "Poe"
}
}
}
},
{
"K": 2,
"V": {
"title": "A Study In Scarlet",
"author": {
"id": 2,
"record": {
"firstName": "Arthur",
"middleName": "Conan",
"lastName": "Doyle"
}
}
}
},
{
"K": 5,
"V": {
"ERROR": 404,
"message": "No book with id 5"
}
}
]
Error entry can be recognized by the ERROR
field, which is not a
valid field name in Epigraph schema (as all fields must start with a
lower case letter).
OK, how about some text, with pagination?
curl -s -g "http://localhost:8888/books[1,2](title,author:record(firstName,lastName),text:plain;count=100)" | jq
[
{
"K": 1,
"V": {
"title": "The Gold Bug",
"author": {
"firstName": "Allan",
"lastName": "Poe"
},
"text": "MANY years ago, I contracted an intimacy with a Mr. William Legrand. He was of an ancient Huguenot f"
}
},
{
"K": 2,
"V": {
"title": "A Study In Scarlet",
"author": {
"firstName": "Arthur",
"lastName": "Doyle"
},
"text": "IN the year 1878 I took my degree of Doctor of Medicine of the University of London, and proceeded t"
}
}
]
We can also ask for some meta-data back:
curl -s -g "http://localhost:8888/books[1,2](title,author:record(firstName,lastName),text:plain;offset=999@(offset,count))" | jq
[
{
"K": 1,
"V": {
"title": "The Gold Bug",
"author": {
"firstName": "Allan",
"lastName": "Poe"
},
"text": {
"meta": {
"offset": 999,
"count": 403
},
"data": "found, indeed, the bristly palmetto; but the whole island, with the exception of this western point, and a line of hard, white beach on the seacoast, is covered with a dense undergrowth of the sweet myrtle, so much prized by the horticulturists of England. The shrub here often attains the height of fifteen or twenty feet, and forms an almost impenetrable coppice, burthening the air with its fragrance"
}
}
},
{
"K": 2,
"V": {
"title": "A Study In Scarlet",
"author": {
"firstName": "Arthur",
"lastName": "Doyle"
},
"text": {
"meta": {
"offset": 999,
"count": 1130
},
"data": "t, which shattered the bone and grazed the subclavian artery. I should have fallen into the hands of the murderous Ghazis had it not been for the devotion and courage shown by Murray, my orderly, who threw me across a pack-horse, and succeeded in bringing me safely to the British lines.\n\nWorn with pain, and weak from the prolonged hardships which I had undergone, I was removed, with a great train of wounded sufferers, to the base hospital at Peshawar. Here I rallied, and had already improved so far as to be able to walk about the wards, and even to bask a little upon the verandah, when I was struck down by enteric fever, that curse of our Indian possessions. For months my life was despaired of, and when at last I came to myself and became convalescent, I was so weak and emaciated that a medical board determined that not a day should be lost in sending me back to England. I was dispatched, accordingly, in the troopship \"Orontes,\" and landed a month later on Portsmouth jetty, with my health irretrievably ruined, but with permission from a paternal government to spend the next nine months in attempting to improve it"
}
}
}
]
This @(offset,count)
part specifies a projection for the meta-data.
count
tells the length of the returned text.
Next section: adding search operation