A RESTful API built with Go and the Gin framework for managing events and user registrations. This project demonstrates a complete backend implementation with authentication, database management, and CRUD operations.
-
User Authentication
- User signup and login
- Password hashing with bcrypt
- JWT-based authentication
- Protected routes with authentication middleware
-
Event Management
- Create, read, update, and delete events
- Event details including name, description, location, and date/time
- User ownership of events
-
Event Registration
- Users can register for events
- Cancel event registrations
- Track event attendees
- Language: Go 1.21.2
- Web Framework: Gin
- Database: SQLite3
- Authentication: JWT (JSON Web Tokens)
- Password Hashing: bcrypt
.
├── main.go # Application entry point
├── db/ # Database initialization and configuration
│ └── db.go
├── models/ # Data models
│ ├── event.go # Event model and database operations
│ └── user.go # User model and authentication
├── routes/ # Route handlers
│ ├── routes.go # Route registration
│ ├── events.go # Event-related endpoints
│ ├── users.go # User authentication endpoints
│ └── register.go # Event registration endpoints
├── middlewares/ # HTTP middlewares
│ └── auth.go # JWT authentication middleware
├── utils/ # Utility functions
│ ├── hash.go # Password hashing utilities
│ └── jwt.go # JWT token generation and validation
└── api-test/ # HTTP request examples for testing
- Go 1.21.2 or higher
- SQLite3
-
Clone the repository
git clone https://github.com/adhirajkar/events-rest-api.git cd events-rest-api -
Install dependencies
go mod download
-
Run the application
go run main.go
The server will start on
http://localhost:8080 -
Database
- The SQLite database (
api.db) will be created automatically on first run - Tables are created automatically via migrations in
db/db.go
- The SQLite database (
POST /signup
Content-Type: application/json
{
"email": "user@example.com",
"password": "yourpassword"
}POST /login
Content-Type: application/json
{
"email": "user@example.com",
"password": "yourpassword"
}GET /eventsGET /events/:idAdd the JWT token from login response to the Authorization header:
POST /events
Authorization: <jwt-token>
Content-Type: application/json
{
"name": "Tech Conference 2025",
"description": "Annual technology conference",
"location": "San Francisco, CA",
"dateTime": "2025-06-15T09:00:00.000Z"
}PUT /events/:id
Authorization: <jwt-token>
Content-Type: application/json
{
"name": "Updated Event Name",
"description": "Updated description",
"location": "New Location",
"dateTime": "2025-06-16T10:00:00.000Z"
}DELETE /events/:id
Authorization: <jwt-token>POST /events/:id/register
Authorization: <jwt-token>DELETE /events/:id/register
Authorization: <jwt-token>The api-test/ directory contains HTTP request files for testing all endpoints. You can use these with:
- REST Client VS Code extension
- Any HTTP client (Postman, Insomnia, etc.)
Example test files:
create-user.http- User signuplogin.http- User loginget-events.http- Fetch all eventscreate-event.http- Create new eventupdate-event.http- Update existing eventdelete-event.http- Delete eventregister.http- Register for eventcancel-registration.http- Cancel event registration
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
email TEXT NOT NULL UNIQUE,
password TEXT NOT NULL
)CREATE TABLE events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT NOT NULL,
location TEXT NOT NULL,
dateTime DATETIME NOT NULL,
user_id INTEGER,
FOREIGN KEY(user_id) REFERENCES users(id)
)CREATE TABLE registrations (
id INTEGER PRIMARY KEY AUTOINCREMENT,
event_id INTEGER,
user_id INTEGER,
FOREIGN KEY(event_id) REFERENCES events(id),
FOREIGN KEY(user_id) REFERENCES users(id)
)- Passwords are hashed using bcrypt before storage
- JWT tokens for stateless authentication
- Protected routes require valid JWT tokens
- SQL prepared statements to prevent SQL injection
- Input validation on all endpoints