This is a simple RESTful app to store some notes in a Lucene index.
Note: you may need enhanced privileges to run this app since it runs on port 80. If you prefer to use a different port, then pass in the
port in the command line as a Java System property -Dserver.port=_port_
before the jar like this:
java -jar -Dserver.port=8080 Notes-all.jar -t
Navigate to build/libs and run the following
java -jar Notes-all.jar -t
That will allow you to hit all the endpoints, but you will get no persistence as it will use a temporary directory
Navigate to build/libs and run the following
java -jar Notes-all.jar -d directory
It will now create your directory and you can persist data between runs
As a bonus you can get the Swagger UI at
Or the harder to read for humans, swagger documentation (used for various code gen utilities) at
Curl statements below are made for Windows commandline, but should work for Linux or if not then some small changes to escaping quotes might be needed.
This will create a note, but shouldn't have an ID.
curl -i -H "Content-Type: application/json" -X POST -d "{"body" : "Pick up milk!"}" http://localhost/api/notes
Lists everything
curl -i -X GET http://localhost/api/notes
Lists the note with the id
curl -i -X GET http://localhost/api/notes{id}
Returns the results of a Lucene search
curl -i -X GET http://localhost/api/notes?query=milk
Delete your note
curl -i -XDELETE http://localhost/api/notes/1
Updates a note. ID must be present in the URL and if present in the note then it must match. In this case we are reserving the ID generation for the database and indicating that the user may not submit their own.
curl -i -H "Content-Type: application/json" -XPUT -d "{ "id": 3, "body" : "email [email protected]"}" http://localhost/api/notes/3
- It's more performant than SQL queries for
where body like '%milk%'
and the results are probably more user friendly. - You can do fuzzy searching
mlk~1
- You can do wildcard matching
mil*
- You can search for multiple terms
milk AND pick
. Just remember to do URL encodingmilk%20AND%20pick
- You can search for phrases
"pick up milk"
- Case is handled
- Basically it's for search
In an app, you know what's used, and more work than brings value is just that. Certainly, if it was being used or being presented in a library I would have implemented and tested it.
Here we use the gradle wrapper. I'm unsure if you will have to download gradle to run them since part of the point of the gradle wrapper is to lock down a version and pulls down its own jar in /gradle/wrapper/gradle-wrapper.jar
.
Navigate to the base directory Notes
and run the following
./gradlew shadowJar
The output will be build/libs/Notes-all.jar
a shadow jar is the same concept as an uber jar or a fat jar.
Navigate to the base directory Notes
and run the following
./gradlew test