TILNotes stands for Today I Learnt Notes. This is a note taking app of what you have learned today. So you can remember what you have learned.
- Go
- GoFiber (Routing)
- GORM (ORM)
- PostgreSQL (DB)
- JWT (Authentication)
- Docker
*Make sure you have Go and PostgreSQL installed on your host machine.
- Clone the project
- via ssh:
git clone [email protected]:mofodox/TILNotes.git
- via https:
git clone https://github.com/mofodox/TILNotes.git
- via ssh:
- Use
go mod download
via the terminal to make sure you have the dependencies (you must be in the project root folder) - Rename the
.env.sample
to.env
in the root folder with this following:DBHost=<insert_postgres_hostname> – defaults to: 127.0.0.1 DBUser=<insert_postgres_username> - defaults to: postgres DBPassword=<insert_postgres_password> - defaults to: password (first time creation) DBName=<insert_database_name> DBPort=<insert_postgres_port> - defaults to: 5432 JWTSecret=tilnotesapi
- Once you have the dependencies installed, to run the API server: type
go run main.go
- To test the server is working, visit
http://localhost:1337/
and you can see a stringHello World
is sent.
*Make sure you have Go and Docker installed on your host machine.
- Clone the project
- via ssh:
git clone [email protected]:mofodox/TILNotes.git
- via https:
git clone https://github.com/mofodox/TILNotes.git
- via ssh:
- Build the custom image:
docker build -t tilnotesapi-server .
- After the image has been successfully built:
docker-compose -up
- Make sure that you have exported the env values in your ~/.zshrc or ~/.bashrc depends on your environment too.
export DBUser=<insert_postgres_username> - defaults to: postgres export DBPassword=<insert_postgres_password> - defaults to: password (first time creation) export DBName=<insert_database_name>
- To test the server is working, visit
http:localhost:8080
and you can see a stringHello World
is sent.
You can play around with TILNotesAPI with a REST API client such as POSTMAN or whichever you prefer.
Have fun!
JWT will be created when the user login, and the jwt token is saved in cookie. If you look in the router
file,
we created a fiber middleware middlewares.AuthRequired
to handle the authorization on the endpoints.
-
POST
/api/v1/users/auth/register
: Register a usercurl --location --request POST 'http://localhost:1337/api/v1/users/auth/register' \ --header 'Content-Type: application/json' \ --data-raw '{ "email": "[email protected]", "first_name": "test", "last_name": "test", "password": "test" }'
-
POST
/api/v1/users/auth/login
: Login a usercurl --location --request POST 'http://localhost:1337/api/v1/users/auth/login' \ --header 'Content-Type: application/json' \ --header 'Cookie: jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Mjg0MDgxMDYsImlzcyI6IjEifQ.y68iacn2rUzdsWGz3pTwq3U-ycw2-dPhWWSfRKOYdsU' \ --data-raw '{ "email": "[email protected]", "password": "test" }'
-
GET
/api/v1/users/auth/current_user
: Retrieve current logged in usercurl --location --request GET 'http://localhost:1337/api/v1/users/auth/current_user' \ --header 'Cookie: jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MjgzNTU0NzgsImlzcyI6IjEifQ.m5N_TqjZ7vpSU-coN2m5YtOku-JeIEfv0nhlWsIidUA'
-
POST
/api/v1/users/auth/logout
: Logout current usercurl --location --request POST 'http://localhost:1337/api/v1/users/auth/logout'
-
GET
/api/v1/notes
: Retrieve all notescurl -X GET \ 'http://localhost:1337/api/v1/notes' \ -H 'Accept: */*' \ -H 'User-Agent: Thunder Client (https://www.thunderclient.io)'
-
GET
/api/v1/notes/:id
: Retrieve a note with id paramcurl -X GET \ 'http://localhost:1337/api/v1/notes/1' \ -H 'Accept: */*' \ -H 'User-Agent: Thunder Client (https://www.thunderclient.io)'
-
POST
/api/v1/notes
: Add a notecurl -X POST \ 'http://localhost:1337/api/v1/notes' \ -H 'Accept: */*' \ -H 'User-Agent: Thunder Client (https://www.thunderclient.io)' \ -H 'Content-Type: application/json' \ -d '{ "title": "Test 1", "content": "Test 1", "category_id": 1, }'
-
PUT
/api/v1/notes/edit/:id
: Edit a note with id paramcurl -X PUT \ 'http://localhost:1337/api/v1/notes/edit/1' \ -H 'Accept: */*' \ -H 'User-Agent: Thunder Client (https://www.thunderclient.io)' \ -H 'Content-Type: application/json' \ -d '{ "title": "Test One", "content": "Test One" }'
-
DELETE
/api/v1/notes/delete/:id
: Remove a note with id paramcurl -X DELETE \ 'http://localhost:1337/api/v1/notes/delete/1' \ -H 'Accept: */*' \ -H 'User-Agent: Thunder Client (https://www.thunderclient.io)'
-
GET
/api/v1/categories
: Retrieve all categoriescurl --location --request GET 'http://localhost:1337/api/v1/categories' \ --header 'Cookie: jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Mjg0MDgxMDYsImlzcyI6IjEifQ.y68iacn2rUzdsWGz3pTwq3U-ycw2-dPhWWSfRKOYdsU'
-
GET
/api/v1/categories/:id
: Retrieve a note with id paramcurl --location --request GET 'http://localhost:1337/api/v1/categories/1' \ --header 'Cookie: jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Mjg0MDgxMDYsImlzcyI6IjEifQ.y68iacn2rUzdsWGz3pTwq3U-ycw2-dPhWWSfRKOYdsU'
-
POST
/api/v1/categories
: Add a categorycurl --location --request POST 'http://localhost:1337/api/v1/categories' \ --header 'Content-Type: application/json' \ --header 'Cookie: jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Mjg0MDgxMDYsImlzcyI6IjEifQ.y68iacn2rUzdsWGz3pTwq3U-ycw2-dPhWWSfRKOYdsU' \ --data-raw '{ "name": "GORM" }'
-
PUT
/api/v1/categories/edit/:id
: Edit a category with id paramcurl -X PUT \ 'http://localhost:1337/api/v1/category/edit/1' \ -H 'Accept: */*' \ -H 'User-Agent: Thunder Client (https://www.thunderclient.io)' \ -H 'Content-Type: application/json' \ -d '{ "title": "Test One", "content": "Test One" }'
-
DELETE
/api/v1/categories/delete/:id
: Remove a category with id paramcurl -X DELETE \ 'http://localhost:1337/api/v1/notes/delete/1' \ -H 'Accept: */*' \ -H 'User-Agent: Thunder Client (https://www.thunderclient.io)'
TILNotesAPI is an open source project. Please feel free to contribute and when contributing, please follow the Code of Conduct.
Feel free to submit issues and enhancement requests.
In general we follow the "fork-and-pull" Git workflow.
- Fork the repo on GitHub
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit a Pull request so that we can review your changes
NOTE: Be sure to merge the latest from "main" branch before making a pull request.