This project is a RESTful API for managing events, built with the Gin framework in Go and SQLite for data storage. It includes JWT-based authentication and authorization to secure the endpoints and ensure that only authorized users can modify event data.
- Create, retrieve, update, and delete events
- User authentication and authorization using JWT
- Event registration and cancellation for authenticated users
- Middleware for token validation and authorization
- Go (Gin Framework)
- SQLite
- JWT for authentication
-
Clone the repository:
git clone https://github.com/Milan-CS03/GO_REST.git cd REST-GO -
Install dependencies:
go mod tidy
-
Set up the database: Ensure SQLite is installed and configure the database as required.
-
Run the application:
go run main.go
-
Register a new user: POST
/signupwith JSON payload:{ "email": "example@abc.com", "password": "password" } -
Login to get JWT token: POST
/loginwith JSON payload:{ "username": "example@abc.com", "password": "password" } -
Use the token to access protected endpoints: Add the token to the
Authorizationheader:Authorization: Bearer your_jwt_token
-
Public Endpoints:
- POST
/signup- Register a new user - POST
/login- Login and obtain a JWT
- POST
-
Protected Endpoints (require JWT):
- GET
/events- Get a list of all events - POST
/events- Create a new event - PUT
/events/:id- Update an event - DELETE
/events/:id- Delete an event - POST
/events/:id/register- Register for an event - DELETE
/events/:id/register- Cancel registration for an event
- GET
This project uses JWT for authentication. After logging in, include the JWT in the Authorization header for protected endpoints.
- JWT Middleware: Validates the token and authorizes the user.