A RESTful API for a personal blogging platform built with Spring Boot.
- Create, read, update, and delete blog posts
- Search posts by title, content, or category
git clone https://github.com/Bahaaio/blog-api
cd blog-api
docker-compose up -d
./mvnw spring-boot:runAPI available at http://localhost:8080
POST /postsReturns 201 Created
Request
{
"title": "10 Reasons Why Coffee Makes You a Better Developer ☕",
"content": "Let's face it, code and coffee go together like semicolons and syntax errors. Here's why your next cup might be the key to your next breakthrough...",
"category": "Developer Life",
"tags": ["coffee", "productivity", "coding", "life-hacks"]
}Response
{
"id": 1,
"title": "10 Reasons Why Coffee Makes You a Better Developer ☕",
"content": "Let's face it, code and coffee go together like semicolons and syntax errors. Here's why your next cup might be the key to your next breakthrough...",
"category": "Developer Life",
"tags": ["coffee", "productivity", "coding", "life-hacks"],
"createdAt": "2024-01-01T12:00:00",
"updatedAt": "2024-01-01T12:00:00"
}GET /postsReturns 200 OK
Response
[
{
"id": 1,
"title": "10 Reasons Why Coffee Makes You a Better Developer ☕",
"content": "Let's face it, code and coffee go together like semicolons and syntax errors. Here's why your next cup might be the key to your next breakthrough...",
"category": "Developer Life",
"tags": ["coffee", "productivity", "coding", "life-hacks"],
"createdAt": "2024-01-01T12:00:00",
"updatedAt": "2024-01-01T12:00:00"
},
{
"id": 2,
"title": "Building APIs That Don't Suck: A Developer's Guide 🚀",
"content": "Your users deserve better than 500 errors and cryptic responses. Here's how to build APIs that developers actually love to use...",
"category": "Web Development",
"tags": ["api", "backend", "best-practices", "spring-boot"],
"createdAt": "2024-01-02T09:30:00",
"updatedAt": "2024-01-02T09:30:00"
}
]GET /posts?term=coffeeReturns 200 OK
[
{
"id": 1,
"title": "10 Reasons Why Coffee Makes You a Better Developer ☕",
"content": "Let's face it, code and coffee go together like semicolons and syntax errors. Here's why your next cup might be the key to your next breakthrough...",
"category": "Developer Life",
"tags": ["coffee", "productivity", "coding", "life-hacks"],
"createdAt": "2024-01-01T12:00:00",
"updatedAt": "2024-01-01T12:00:00"
}
]Searches title, content, and category fields
GET /posts/{id}Returns 200 OK or 404 Not Found
Response
{
"id": 1,
"title": "10 Reasons Why Coffee Makes You a Better Developer ☕",
"content": "Let's face it, code and coffee go together like semicolons and syntax errors. Here's why your next cup might be the key to your next breakthrough...",
"category": "Developer Life",
"tags": ["coffee", "productivity", "coding", "life-hacks"],
"createdAt": "2024-01-01T12:00:00",
"updatedAt": "2024-01-01T12:00:00"
}PUT /posts/{id}Returns 200 OK or 404 Not Found
Request
{
"title": "Why Debugging at 3 AM Always Finds the Bug 🐛",
"content": "There's something magical about late-night debugging sessions. Maybe it's the quiet, maybe it's the desperation, but somehow that elusive bug always reveals itself...",
"category": "Developer Life",
"tags": ["debugging", "midnight-coding", "developer-humor"]
}Response
{
"id": 1,
"title": "Why Debugging at 3 AM Always Finds the Bug 🐛",
"content": "There's something magical about late-night debugging sessions. Maybe it's the quiet, maybe it's the desperation, but somehow that elusive bug always reveals itself...",
"category": "Developer Life",
"tags": ["debugging", "midnight-coding", "developer-humor"],
"createdAt": "2024-01-01T12:00:00",
"updatedAt": "2024-01-01T12:30:00"
}DELETE /posts/{id}Returns 204 No Content or 404 Not Found
The API includes input validation for all POST/PUT requests:
| Field | Constraints |
|---|---|
| title | 4-200 characters, unique |
| content | Max 10,000 characters |
| category | Max 50 characters |
| tags | Max 10 tags, non-null |
Returns 400 Bad Request with field-specific error messages:
[
{ "title": "size must be between 4 and 200" },
{ "content": "must not be blank" }
]Returns 404 Not Found when requesting non-existent posts:
{
"timestamp": "2024-01-01T12:00:00",
"status": 404,
"error": "Not Found",
"path": "/posts/100"
}Inspired by roadmap.sh Blogging Platform API