This project is a Go-powered REST API for managing event bookings. It allows users to create, update, delete, and view events, as well as manage user registrations for these events.
The Event Booking API provides the following endpoints:
-
GET /events
- Description: Get a list of available events.
- Authentication: Not required.
-
GET /events/{id}
- Description: Get details of a specific event by ID.
- Authentication: Not required.
-
POST /events
- Description: Create a new bookable event.
- Authentication: Required.
- Authorization: Only authenticated users can create events.
-
PUT /events/{id}
- Description: Update an event.
- Authentication: Required.
- Authorization: Only the creator of the event can update it.
-
DELETE /events/{id}
- Description: Delete an event.
- Authentication: Required.
- Authorization: Only the creator of the event can delete it.
-
POST /signup
- Description: Register a new user.
- Authentication: Not required.
-
POST /login
- Description: Authenticate a user and receive a JWT token.
- Authentication: Not required.
-
POST /events/{id}/register
- Description: Register a user for an event.
- Authentication: Required.
-
DELETE /events/{id}/register
- Description: Cancel a registration for an event.
- Authentication: Required.
The API uses JWT (JSON Web Tokens) for authentication. After signing up, users can log in to receive a JWT, which must be included in the Authorization header for all requests that require authentication.
Certain actions, such as updating or deleting an event, are restricted to the user who created the event. This is enforced through the API's authorization mechanisms.
- Clone the repository:
git clone https://github.com/Alextz307/go-rest-api.git
- Navigate to the project directory:
cd go-rest-api - Install dependencies:
go mod tidy
- Run the application:
go run main.go
To use the API, you'll need to send HTTP requests to the corresponding endpoints. You can use tools like curl, Postman, or any HTTP client of your choice.
Example:
- Registering a new user
curl -X POST http://localhost:8080/signup -d '{"username":"user1","password":"pass123"}'- Creating a new event (Authentication required)
curl -X POST http://localhost:8080/events -H "Authorization: Bearer YOUR_JWT_TOKEN" -d '{"name":"Event 1","date":"2024-08-20"}'