# README
Go Simple CRUD Application with MySql and Gin Framework
This is a simple CRUD (Create, Read, Update, Delete) application built in Go using the Gin Web Framework and MySql. The application manages a list of todos
, allowing users to create, read, update, and delete todo
items.
Features
- Create a Todo: Add a new
todo
item with a ID, description, and completion status. - Read Todos: Retrieve the list of all
todos
or get details for a specifictodo
. - Update a Todo: Edit an existing
todo
by updating its description and/or completion status. - Delete a Todo: Remove a
todo
item from the list.
Endpoints
GET /todos
- Retrieves the full list of todos.POST /todos
- Creates a new todo item.GET /todos/:id
- Retrieves details of a specific todo by ID.PATCH /todos/:id
- Toggles the completion status of a todo.PUT /todos/:id
- Updates the description and/or completion status of a specific todo.DELETE /todos/:id
- Deletes a specific todo by ID.
Quick Start
Prerequisites
- Go (version 1.23.3 or higher)
- Gin Web Framework
- MySql
- Docker
Installation
-
Clone the repository:
git clone https://github.com/aleksandr-slobodian/go-simple-crud-mysql cd go-simple-crud-mysql
-
Install dependencies:
go mod download
-
Run the MySql server:
docker-compose up -d
-
Run the migration:
Install migrate and run the following command:
make migrate-up
-
Run the application:
with go:
go run main.go
with Air - Live reload:
air
Usage
-
Create a new todo:
curl -X POST -H "Content-Type: application/json" -d '{"item": "Buy groceries", "completed": false}' http://localhost:9191/todos
-
Retrieve all todos:
curl http://localhost:9191/todos
-
Retrieve a specific todo:
curl http://localhost:9191/todos/1
-
Update a todo:
curl -X PUT -H "Content-Type: application/json" -d '{"item": "Buy groceries", "completed": true}' http://localhost:9191/todos/1
-
Update todo's completed status:
curl -X PUTCH http://localhost:9191/todos/1
-
Delete a todo:
curl -X DELETE http://localhost:9191/todos/1
License
This project is licensed under the MIT License.