A Go-powered REST API for event booking, management and user authentication.
- Empowered by the high-performance web framework Gin
- JWT(JSON Web Tokens)-based authorization for protected routes using JWT
- Secure password handling by
bcrypt
from crypto - RESTful architecture
-
Clone the repository:
git clone https://github.com/RenkeHuang/event_booking_api.git cd event_booking_api
-
Install dependencies:
go mod download # or `go mod tidy` if error occurs
-
Start the API server locally:
go run .
The server will start at http://localhost:8080
POST http://localhost:8080/signup
- Register for a new userPOST http://localhost:8080/login
- Login and get JWT token
GET http://localhost:8080/events
- List all eventsGET http://localhost:8080/events/:id
- Get details of an eventPOST http://localhost:8080/events
- Create a new eventPUT http://localhost:8080/events/:id
- Update an eventDELETE http://localhost:8080/events/:id
- Delete an event
POST http://localhost:8080/events/:id/register
- Book an eventDELETE http://localhost:8080/events/:id/register
- Cancel a bookingGET http://localhost:8080/events/:id/register
- View all registrations
All protected endpoints require a JWT token which you can obtain by registering and logging in:
# Register a new user
curl -X POST http://localhost:8080/signup \
-H "Content-Type: application/json" \
-d '{"username": "user1", "password": "password123", "email": "user1@example.com"}'
# Login to get a token
curl -X POST http://localhost:8080/login \
-H "Content-Type: application/json" \
-d '{"username": "user1", "password": "password123"}'
Use the returned token in the authorization header, e.g. cancel the registration
curl -X DELETE http://localhost:8080/events/1/register \
-H "Authorization: YOUR_TOKEN_HERE"
├── db
│ └── db.go
├── main.go
├── middlewares
│ └── auth.go
├── models
│ ├── event.go
│ └── user.go
├── routes
│ ├── events.go
│ ├── register.go
│ ├── routes.go
│ └── users.go
└── utils
├── hash.go
└── jwt.go
MIT License