████████╗██████╗ █████╗ ██╗ ██╗███████╗██╗ ███████╗████████╗ █████╗ ██████╗ ████████╗
╚══██╔══╝██╔══██╗██╔══██╗██║ ██║██╔════╝██║ ██╔════╝╚══██╔══╝██╔══██╗██╔══██╗╚══██╔══╝
██║ ██████╔╝███████║██║ ██║█████╗ ██║ ███████╗ ██║ ███████║██████╔╝ ██║
██║ ██╔══██╗██╔══██║╚██╗ ██╔╝██╔══╝ ██║ ╚════██║ ██║ ██╔══██║██╔══██╗ ██║
██║ ██║ ██║██║ ██║ ╚████╔╝ ███████╗███████╗███████║ ██║ ██║ ██║██║ ██║ ██║
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝
██████╗ ███████╗███████╗████████╗ █████╗ ██████╗ ██╗
██╔══██╗██╔════╝██╔════╝╚══██╔══╝ ██╔══██╗██╔══██╗██║
██████╔╝█████╗ ███████╗ ██║ ███████║██████╔╝██║
██╔══██╗██╔══╝ ╚════██║ ██║ ██╔══██║██╔═══╝ ██║
██║ ██║███████╗███████║ ██║ ██║ ██║██║ ██║
╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝
A nice, simple REST API template written in Java using Camel with Netty which includs an ErrorHandler and a few sample requests. Swagger support included as well.
This is a work in progress - contributions are welcome
You will need gradle to build (and "deploy" [optional] ).
Mode | How | How (in debug) |
---|---|---|
Development option 1 | gradle run |
gradle run --debug-jvm |
Development option 2 | run com.travelstart.api.Boot from IDE | run com.travelstart.api.Boot in debug mode in IDE |
Externally | gradle installDist , run script: build/install/java-rest-api-template/bin/java-rest-api-template |
N/A |
- REST Routes are defined in com.travelstart.api.RestRoutes
- Errors are handled in com.travelstart.api.handler.ErrorHandler
- Request/Response content handler for logging is in com.travelstart.api.handler.LoggingHandler
- Runs on port 8890 by default - to customise, see com.travelstart.api.Boot.PORT
- Uses CPU Cores x 2 workers - see com.travelstart.api.Boot.WORKER_COUNT to customise
- Eclipse:
gradle eclipse
- IntelliJ IDEA:
gradle idea
- NetBeans: use the gradle plugin
/api/ping
- POST/GET that returns a fixed string response/api/booking
- PUT to create a booking - returns the ID in the response/api/booking/{id}
- POST to update a booking given the ID/api/booking/{id}
- GET to retrieve a booking given the ID
docker create --rm --name swagger-rest-template -p 8081:8080 -e API_URL=http://localhost:8890/api-doc/swagger.json swaggerapi/swagger-ui:v2.2.9
docker start swagger-rest-template
- goto: http://localhost:8081/ and enter http://localhost:8890/api-doc/swagger.json in the box
gradle test jacocoTestReport
test result reports at:
- code coverage: java-rest-api-template/build/reports/jacoco/test/html/index.html
- test summary: java-rest-api-template/build/reports/tests/test/index.html
The following system properties can be set to customise the server:
System Property | What |
---|---|
server.host |
The binding address - default is localhost |
server.port |
The port the server listens on - default is 8890 |
server.workers |
The number of works (threads) available for requests - default is CPU Cores x 2 |
server.max-content-length |
The maximum upload size - default is 1MB |