A simple TODO application built with Golang and React.js.
This project demonstrates a full-stack TODO application with:
- Backend: Golang using the Fiber framework and Gorm ORM with MySQL.
- Frontend: A React.js application located in the
client/
directory.
The application supports creating, updating, deleting, and reordering TODO items via a RESTful API.
- Create Todo: Add a new TODO item.
- Retrieve Todos: Fetch the list of TODO items.
- Update Todo: Modify an existing TODO item.
- Delete Todo: Remove a TODO item.
- Reorder Todos: Update the order of TODO items.
- Golang: Version 1.22.3 or later.
- MySQL: A running MySQL database.
- Node.js & npm/yarn: For the React frontend.
git clone https://github.com/angelo1121/go-react-todo.git
cd go-react-todo
-
Create a
.env
FileIn the root directory, create a
.env
file with the following content (update the values as needed):MYSQL_URI="your_mysql_connection_string" SERVER_PORT=3000
-
Install Go Dependencies
Run the following command to download the necessary packages:
go mod download
-
Run Database Migrations and Start the Server
The
main.go
file automatically migrates the schema and starts the Fiber server:go run main.go
The server listens on the port specified in your
.env
file.
-
Navigate to the Client Directory
cd client
-
Install Dependencies
Use npm (or yarn) to install the required packages:
npm install
-
Start the React Development Server
npm run dev
The React app will run on its port (usually
5173
) and communicate with the Golang backend.
The backend exposes the following endpoints:
-
GET /api/todos
Retrieves a list of all TODO items. -
POST /api/todos
Creates a new TODO item. Body Parameters:body
(string, required): The content of the TODO item.completed
(boolean, optional): Completion status (default isfalse
).order
(number, optional): Position/order of the TODO item.
-
PATCH /api/todos/:id
Updates an existing TODO item identified byid
. -
DELETE /api/todos/:id
Deletes a TODO item byid
. -
PUT /api/todos/order
Updates the order of the TODO items. Body: An array of objects containing theid
of the TODO item. The order in the array represents the new order.