A simple Spring Boot REST API that serves quotes. This service is the backend for the 03-consuming-rest tutorial.
03-quote-service/
├── pom.xml
├── src/main/java/com/example/quoteservice/
│ ├── QuoteServiceApplication.java # Main entry point
│ ├── QuoteController.java # REST endpoints
│ ├── Quote.java # Record for JSON response
│ └── Value.java # Record for nested JSON object
├── src/test/java/com/example/quoteservice/
│ └── QuoteControllerTest.java # Endpoint tests
├── src/main/resources/
│ └── application.properties
└── docs/
├── DEVELOPER_NOTES.md # My developer notes
├── images/ # Screenshots
├── setup/
│ └── spring-initializr.md # Project setup from start.spring.io
├── concepts/
│ └── quote-controller.md # Explains the controller and Java Streams
├── reference/
│ └── guide.md # Spring guide reference
└── adr/
├── ADR-0001-split-provider-consumer.md # Why separate modules
├── ADR-0002-rest-api-shape.md # API design decisions
└── ADR-0003-use-threadlocalrandom.md # Why ThreadLocalRandom
| Method | Path | Description |
|---|---|---|
| GET | /api/ |
All quotes |
| GET | /api/random |
Random quote |
| GET | /api/{id} |
Quote by ID (1-10), or 404 if not found |
{
"type": "success",
"value": {
"id": 1,
"quote": "Working with Spring Boot is like pair-programming with the Spring developers."
}
}./mvnw spring-boot:runThe service starts on http://localhost:8080.
curl http://localhost:8080/api/random
curl http://localhost:8080/api/
curl http://localhost:8080/api/1./mvnw testTests cover all three endpoints and verify correct JSON responses.
This service provides quotes in a specific JSON format that the 03-consuming-rest consumer expects.
| Field | Type | Description |
|---|---|---|
type |
string | "success" for valid responses, "failure" for 404 |
value |
object | Contains id (int) and quote (string) |
| Endpoint | Success | Not Found |
|---|---|---|
GET /api/ |
200 (array of quotes) | N/A |
GET /api/random |
200 (single quote) | N/A |
GET /api/{id} |
200 (single quote) | 404 (type: "failure") |
- 03-consuming-rest - REST client that consumes this service
- Spring Guide: Consuming a RESTful Web Service
- Spring Guide: Building a RESTful Web Service - background on REST controllers
