This is a simple blog post API that allows users to create, read, update, and delete blog posts. It uses Go's net/http package to handle HTTP requests and Gorilla's mux package to handle routing. This project serves as a practical exercise to solidify understanding of CRUD functionality in Go.
- Create a new blog post:
POST /posts - Read all blog posts:
GET /posts - Read a specific blog post by ID:
GET /posts/{id} - Update a specific blog post by ID:
PUT /posts/{id} - Delete a specific blog post by ID:
DELETE /posts/{id}
You can use tools like curl or Postman to interact with the API endpoints. Here are some example requests:
curl -X POST http://localhost:8080/posts \
-H "Content-Type: application/json" \
-d '{"id":1,"author":"Alice","title":"First Post","content":"Hello, world!"}'curl http://localhost:8080/postscurl http://localhost:8080/posts/1curl -X PUT http://localhost:8080/posts/1 \
-H "Content-Type: application/json" \
-d '{"id":1,"author":"Alice","title":"Updated Title","content":"Updated content"}'curl -X DELETE http://localhost:8080/posts/1- Ensure Go is installed.
- Clone this repository.
- Run:
go mod tidy
go run main.goYour API server will start on http://localhost:8080.
- Add persistent storage (e.g., a database).
- Implement input validation and error handling.
- Secure the API with authentication.
Yangedue John Avalumun