A RESTful API for a blogging platform built with Go. This project provides endpoints to create, read, update, and delete blog posts with filtering capabilities.
- RESTful API architecture
- CRUD operations for blog posts
- SQLite database for data persistence
- Search and filter posts by terms
- JSON response format
- Structured error handling
- main.go: Entry point of the application
- routes/api.go: API route definitions
- handlers/post_handler.go: HTTP request handlers for blog posts
- models/post.go: Data structures for blog posts
- database/:
- db.go: Database connection and migration setup
- blog.db: SQLite database file
- Go (Golang)
- SQLite (via modernc.org/sqlite)
- Standard library HTTP server
- JSON for data interchange
- Go 1.18 or higher
- Git
-
Clone the repository:
git clone https://github.com/yourusername/blogging-platform-api.git cd blogging-platform-api -
Install dependencies:
go mod download
-
Run the application:
go run main.go
-
The server will start on port 8800. You can access it at http://localhost:8800
GET /ping: Check if the API is running
GET /posts: Get all blog posts- Query parameters:
term: Filter posts by title, content, or category
- Query parameters:
POST /posts: Create a new blog postGET /posts/{id}: Get a specific blog post by IDPUT /posts/{id}: Update a specific blog postDELETE /posts/{id}: Delete a specific blog post
Request:
POST /posts
Content-Type: application/json
{
"title": "Getting Started with Go",
"content": "Go is a statically typed, compiled programming language...",
"category": "Programming",
"tags": ["golang", "programming", "tutorial"]
}Response:
{
"message": "Post created successfully",
"data": {
"id": 1,
"title": "Getting Started with Go",
"content": "Go is a statically typed, compiled programming language...",
"category": "Programming",
"tags": ["golang", "programming", "tutorial"],
"created_at": "2025-05-15T03:49:46.547885Z",
"updated_at": "2025-05-15T03:49:46.547885Z"
}
}Request:
GET /postsResponse:
{
"message": "Posts retrieved successfully",
"data": [
{
"id": 1,
"title": "Getting Started with Go",
"content": "Go is a statically typed, compiled programming language...",
"category": "Programming",
"tags": ["golang", "programming", "tutorial"],
"created_at": "2025-05-15T03:49:46.547885Z",
"updated_at": "2025-05-15T03:49:46.547885Z"
}
// ...
]
}The API returns appropriate HTTP status codes and error messages in case of failures:
400 Bad Request: Invalid input data404 Not Found: Resource not found405 Method Not Allowed: HTTP method not supported for the endpoint500 Internal Server Error: Server-side error
- Define new routes in
routes/api.go - Create handlers in
handlers/directory - Add models in
models/directory if needed - Update database migrations in
database/db.goif needed
You can import the provided Postman collection for testing the API endpoints:
- roadmap.sh for the project inspiration
- Created by jaygaha