Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Quote Service

Coverage Mutation SpotBugs

A simple Spring Boot REST API that serves quotes. This service is the backend for the 03-consuming-rest tutorial.

File Index

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

Endpoints

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

JSON Response

{
  "type": "success",
  "value": {
    "id": 1,
    "quote": "Working with Spring Boot is like pair-programming with the Spring developers."
  }
}

Terminal output from curl http://localhost:8080/api/random

Screenshot 2025-12-11 at 12 45 55 AM

Run

./mvnw spring-boot:run

The service starts on http://localhost:8080.

Test the Endpoints

curl http://localhost:8080/api/random
curl http://localhost:8080/api/
curl http://localhost:8080/api/1

Run Tests

./mvnw test

Tests cover all three endpoints and verify correct JSON responses.

API Contract

This service provides quotes in a specific JSON format that the 03-consuming-rest consumer expects.

Response Format

Field Type Description
type string "success" for valid responses, "failure" for 404
value object Contains id (int) and quote (string)

Status Codes

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")

Related