API REST in sola lettura che espone citazioni/fatti divertenti sui programmatori (tipi: backend, frontend, generic) in JSON. Base URL: http://localhost:8080/api/v1/phrases. Documentazione dettagliata e stato dei miglioramenti: vedi PDR-Programmers-Facts-API.md.
Le credenziali del database non sono nel repository. Prima di avviare l'app o Docker:
- Copy
.env.exampleto.env:
cp .env.example .env(Linux/macOS) or rename/copy by hand on Windows. - Open
.envand enter values for:
- Docker:
POSTGRES_USER,POSTGRES_PASSWORD,POSTGRES_DB(required fordocker-compose). - Local Execution (Spring without Docker):
SPRING_DATASOURCE_URL,SPRING_DATASOURCE_USERNAME,SPRING_DATASOURCE_PASSWORD(e.g.,jdbc:postgresql://localhost:5434/programmers-apiif Postgres is running locally on port 5434).
Never commit the .env file (it's in .gitignore).
| Metodo | Endpoint | Descrizione |
|---|---|---|
| GET | /all |
All sentences |
| GET | /random |
Una frase casuale |
| GET | /random-explicit |
A random phrase (404 se no phrase) |
| GET | /{type} |
Phrases by type (frontend, backend, generic); invalid type → "generic" |
| GET | /by-type?type=backend |
Phrases for type (query param; type required and valid, otherwise 400) |
| GET | /id/{id} |
Phrase for ID (404 if nonexistent) |
| GET | /ping |
Health check (204 No Content) |
In case of error the response is JSON: { "error": "...", "code": "400|404|500", "timestamp": "..." }.
curl http://localhost:8080/api/v1/phrases/randomResponse:
{
"data": {
"id": 24,
"phrase": "The first rule of debugging: Don’t make it worse.",
"type": "generic"
}
}you can retrieve a list of quotes filtered by a specific type (backend, frontend, or generic).
curl http://localhost:8080/api/v1/phrases/by-type?type=backend Response
{
"data": [
{
"id": 1,
"phrase": "Backend developers always say, 'It worked on my local server.'",
"type": "backend"
},
{
"id": 4,
"phrase": "Backend developers don’t fear downtime; they fear 'urgent deployments.'",
"type": "backend"
}
]
}
This API serves up quirky quotes that programmers can’t debug away!
If you enjoy this api, or just love programming, please donate to:
Gianpiero Ferraro(always me lol) |
