Skip to content

Bahaaio/blog-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📝 Blog API

Java Spring Boot MySQL Docker

A RESTful API for a personal blogging platform built with Spring Boot.

Features

  • Create, read, update, and delete blog posts
  • Search posts by title, content, or category

Quick Start

git clone https://github.com/Bahaaio/blog-api
cd blog-api
docker-compose up -d
./mvnw spring-boot:run

API available at http://localhost:8080

API Endpoints

Create Blog Post

POST /posts

Returns 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 All Posts

GET /posts

Returns 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"
  }
]

Search Posts

GET /posts?term=coffee

Returns 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 Single Post

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

Update Post

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 Post

DELETE /posts/{id}

Returns 204 No Content or 404 Not Found

Validation

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

Error Responses

Validation Error

Returns 400 Bad Request with field-specific error messages:

[
  { "title": "size must be between 4 and 200" },
  { "content": "must not be blank" }
]

Not Found Error

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Languages