This project is a REST API built with the Gin framework in Go. It provides user and event management functionalities, including user registration, login, event creation, updating, deletion, and user registration for events.
-
User Management:
- User Signup
- User Login
- Password Hashing and Verification
-
Event Management:
- Create Event
- Update Event
- Delete Event
- Register for Event
-
Database:
- SQLite database for storing user and event data
- Write-Ahead Logging (WAL) mode for better concurrency
-
Security:
- Password hashing using Argon2
- Authentication middleware for protected routes
- Go 1.16 or higher
- SQLite3
- Clone the repository:
git clone https://github.com/mdombrov-33/gin-rest-api.git
cd gin-rest-api
- Install dependencies:
go mod tidy
- Build the application:
go build -o gin-rest-api
- Run the application:
./gin-rest-api
- Signup: POST /signup:
Request body:
{
"email": "testuser@gmail.com",
"password": "test"
}
Response: 201 Created
{
"message": "User Created!"
}
- Login: POST /login:
Request body:
{
"email": "testuser@gmail.com",
"password": "test"
}
Response: 200 OK
{
"message": "Login successful!",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3R1c2VyQGdtYWlsLmNvbSIsImV4cCI6MTczMDE4NjYzMSwidXNlcklkIjo1fQ.aEZHPT_HdpHf6S3I-oIkgfHLYHUYFrBvXFlQQDaMMVA"
}
- Create Event: POST /events
Request body:
authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3R1c2VyQGdtYWlsLmNvbSIsImV4cCI6MTczMDE4NjYzMSwidXNlcklkIjo1fQ.aEZHPT_HdpHf6S3I-oIkgfHLYHUYFrBvXFlQQDaMMVA
{
"title": "Event Title",
"description": "Event Description",
"location": "Event Location",
"dateTime": "2025-12-31T23:59:59Z"
}
Response: 201 Created
{
"event": {
"ID": 1,
"Title": "Event Title",
"Description": "Event Description",
"Location": "Event Location",
"DateTime": "2025-12-31T23:59:59Z",
"UserID": 1
},
"message": "Event Created!"
}
- Get All Events: GET /events
Response: 200 OK
[
{
"ID": 1,
"Title": "Event Title",
"Description": "Event Description",
"Location": "Event Location",
"DateTime": "2025-12-31T23:59:59Z",
"UserID": 1
}
]
- Get Single Event: GET /events/:id
Response: 200 OK
{
"ID": 1,
"Title": "Event Title",
"Description": "Event Description",
"Location": "Event Location",
"DateTime": "2025-12-31T23:59:59Z",
"UserID": 1
}
- Update Event: PUT /events/:id
Request Body:
authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3R1c2VyQGdtYWlsLmNvbSIsImV4cCI6MTczMDE4NjYzMSwidXNlcklkIjo1fQ.aEZHPT_HdpHf6S3I-oIkgfHLYHUYFrBvXFlQQDaMMVA
{
"title": "New Event Title",
"description": "New Event Description",
"location": "New Event Location",
"dateTime": "2065-12-31T23:59:59Z"
}
Response: 200 OK
{
"event": {
"ID": 1,
"Title": "New Event Title",
"Description": "New Event Description",
"Location": "New Event Location",
"DateTime": "2065-12-31T23:59:59Z",
"UserID": 1
},
"message": "Event updated!"
}
- Delete Event: DELETE /events/:id
Request Body:
authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3R1c2VyQGdtYWlsLmNvbSIsImV4cCI6MTczMDE4NjYzMSwidXNlcklkIjo1fQ.aEZHPT_HdpHf6S3I-oIkgfHLYHUYFrBvXFlQQDaMMVA
Response: 200 OK
{
"event": {
"ID": 1,
"Title": "Event Title",
"Description": "Event Description",
"Location": "Event Location",
"DateTime": "2025-12-31T23:59:59Z",
"UserID": 1
},
"message": "Event deleted!"
}
- Register for Event: POST /events/:id/register
Request Body:
authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3R1c2VyQGdtYWlsLmNvbSIsImV4cCI6MTczMDE4NjYzMSwidXNlcklkIjo1fQ.aEZHPT_HdpHf6S3I-oIkgfHLYHUYFrBvXFlQQDaMMVA
Response: 201 Created
{
"message": "Successfully registered for the event"
}
- Cancel Registration for Event: DELETE /events/:id/register
Request body:
authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3R1c2VyQGdtYWlsLmNvbSIsImV4cCI6MTczMDE4NjYzMSwidXNlcklkIjo1fQ.aEZHPT_HdpHf6S3I-oIkgfHLYHUYFrBvXFlQQDaMMVA
Response: 200 OK
{
"message": "Successfully canceled registration"
}