A RESTful API for managing notes using Go, PostgreSQL (via Docker), and GORM with UUIDs.
- CRUD operations for notes
- UUIDs for note IDs
- Environment-based configuration using
.envfiles - PostgreSQL as the database (via Docker)
- GORM for ORM (Object-Relational Mapping)
- Signup & Login added.
- Token-based authentication ( JWT ).
- API Documentation (Swagger)
- And many more to be added 🔥
- Go (v1.18+)
- Docker (for PostgreSQL)
- Git
- Go modules (handled via
go mod)
git clone https://github.com/Shihab-Munna/smart-notes-api.gitNavigate into the project directory and run:
cd smart-notes-api
go mod tidyPull the PostgreSQL Docker image and run the container:
docker run --name smart_note_db -e POSTGRES_USER=smart_note_user -e POSTGRES_PASSWORD=password -e POSTGRES_DB=smart_note -p 5432:5432 -d postgresWait for the container to start up, then check if it's running by executing:
docker psEnable the UUID extension:
Once the container is running, access the PostgreSQL instance by running:
docker exec -it smart_note_db psql -U smart_note_user -d smart_noteRun the following SQL command to enable the UUID extension:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";Exit the PostgreSQL shell:
\qCopy the .env.example file to create your own .env file:
cp .env.example .envOpen the .env file and update the placeholder values with your actual PostgreSQL connection information:
PORT=5001
DB_DSN=host=localhost user=smart_note_user password=password dbname=smart_note port=5432 sslmode=disableNote: Replace password with the actual password you set in the Docker command.
Run the Go application:
go run main.goIf everything is set up correctly, the server should now be running at http://localhost:5001.
-
Create a new note:
- URL:
POST /notes - Description: Create a new note.
- Request Body (JSON):
{ "title": "Note Title", "content": "Note content goes here" }- Response (Success 201):
{ "id": "uuid-of-note", "title": "Note Title", "content": "Note content goes here" } - URL:
-
Retrieve all notes:
- URL:
GET /notes - Description: Fetch all notes.
- Response (Success 200):
[ { "id": "uuid-of-note", "title": "Note Title", "content": "Note content goes here" } ] - URL:
-
Retrieve a note by UUID:
- URL:
GET /notes/{id} - Description: Retrieve a note by its UUID.
- Response (Success 200):
{ "id": "uuid-of-note", "title": "Note Title", "content": "Note content goes here" } - URL:
-
Update a note by UUID:
- URL:
PUT /notes/{id} - Description: Update a note by its UUID.
- Request Body (JSON):
{ "title": "Updated Title", "content": "Updated content goes here" }- Response (Success 200):
{ "id": "uuid-of-note", "title": "Updated Title", "content": "Updated content goes here" } - URL:
-
Delete a note by UUID:
- URL:
DELETE /notes/{id} - Description: Delete a note by its UUID.
- Response (Success 204 - No Content)
- URL:
- Modify the
.env.examplefile as needed and ensure your environment variables are set up correctly before running the project locally. - Use
go mod tidyto keep dependencies clean and up to date.
Feel free to fork the repository and make contributions. For significant changes, please open an issue first to discuss what you would like to change.
Copyright (c) 2024 Shihab Munna
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.