This is a simple RESTful API for managing notes built with Go and the Gin framework.
- Create, read, update, and delete (CRUD) notes.
- Rate limiting for API requests.
- Validation for note inputs.
- Cross-Origin Resource Sharing (CORS) support.
Before you begin, ensure you have met the following requirements:
- Go (v1.16 or higher) installed on your machine.
- MySQL database server running locally or at the specified host.
To get started with this project, follow these steps:
-
Clone this repository to your local machine:
git clone https://github.com/solomonbaez/SB-Go-NAPI
-
Change into the project directory:
cd SB-Go-NAPI -
Install project dependencies:
go mod tidy
-
Set up your MySQL database and update the database connection configuration in the
api/config/cfg.gofile:const ( DBUSER = "your-username" DBPASSWORD = "your-password" DBNET = "tcp" DBHOST = "127.0.0.1:3306" DBPORT = "3306" DBNAME = "your-db-name" DBLIMIT = 1 // rate limit - default: 1 request / second )
-
Build and run the API:
go run main.go
-
Your API should now be running at
http://localhost:8000.
The following API endpoints are available:
POST /notes- Create a new note.GET /notes- Retrieve a list of all notes.GET /notes/:id- Retrieve a specific note by ID.PUT /notes/:id- Update a specific note by ID.DELETE /notes/:id- Delete a specific note by ID.
Here are some example requests using curl to interact with the API:
-
Create a new note:
curl -X POST -H "Content-Type: application/json" -d '{"title": "New Note", "content": "This is a new note."}' http://localhost:8000/notes
-
Retrieve all notes:
curl http://localhost:8000/notes
-
Retrieve a specific note by ID:
curl http://localhost:8000/notes/1
-
Update a note by ID:
curl -X PUT -H "Content-Type: application/json" -d '{"title": "Updated Note", "content": "This note has been updated."}' http://localhost:8000/notes/1
-
Delete a note by ID:
curl -X DELETE http://localhost:8000/notes/1
- Create test suite (tests/fuzz).
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
- Fork the repository on GitHub.
- Clone your forked repository to your local machine.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push your changes to your fork on GitHub.
- Open a pull request to the main repository.
This project is licensed under the MIT License - see the LICENSE file for details.