This project is a simple REST API built using Go. It demonstrates the basic principles of building a RESTful service, including handling HTTP requests, routing, authentication, and responding with JSON data.
The Go Events REST API provides endpoints to manage a collection of events, creating new users, and registering users to "attend" events.
It supports the following operations:
- Create a new user
- Log in a user
- Create a new event
Auth Required
- Retrieve all events
- Retrieve a single event by ID
- Update an existing event by ID
Auth Required
Creator Only
- Delete an event by ID
Auth Required
Creator Only
- Register a logged in user for an event by ID
Auth Required
- Cancel registration of a logged in user for an event by ID
Auth Required
- Retrieve all registered users for an event by ID
Auth Required
Creator Only
- URL:
/users
- Method:
POST
- Description: Creates a new user.
- Request Body:
{ "email": "[email protected]", "password": "password123" }
- Response:
{ "message": "New user successfully created" }
- URL:
/login
- Method:
POST
- Description: Logs in a user.
- Request Body:
{ "email": "[email protected]", "password": "password123" }
- Response:
{ "message": "Login successful", "token": "jwt-token" }
- URL:
/events
- Method:
GET
- Description: Retrieves a list of all events.
- Response:
{ "events": [ { "title": "Event 1", "description": "Description for event 1", "location": "Location of for event 1", "datetime": "datetime as string in ISO8601 format" }, ... ] }
- URL:
/events/{id}
- Method:
GET
- Description: Retrieves a single event by its ID.
- Response:
{ "event": { "title": "Event 1", "description": "Description for event 1", "location": "Location of for event 1", "datetime": "datetime as string in ISO8601 format" } }
- URL:
/events
- Method:
POST
- Authorization: Required (JWT in "Authorization" header)
- Authorization Level: Logged In
- Description: Creates a new event.
- Request Body:
{ "title": "Event 1", "description": "Description for event 1", "location": "Location of for event 1", "datetime": "datetime as string in ISO8601 format" }
- Response:
{ "message": "POST successful", "event": { "title": "Event 1", "description": "Description for event 1", "location": "Location of for event 1", "datetime": "datetime as string in ISO8601 format" } }
- URL:
/events/{id}
- Method:
PUT
- Authorization: Required (JWT in "Authorization" header)
- Authorization Level: Logged In, Creator Only
- Description: Updates an existing event by its ID.
- Request Body:
{ "title": "Updated Event", "description": "Description for updated event", "location": "Location for updated event", "datetime": "Updated datetime as string in ISO8601 format" }
- Response:
{ "message": "Successfully updated event" }
- URL:
/events/{id}
- Method:
DELETE
- Authorization: Required (JWT in "Authorization" header)
- Authorization Level: Logged In, Creator Only
- Description: Deletes an event by its ID.
- Response:
{ "message": "Successfully deleted event" }
- URL:
/events/{id}/register
- Method:
POST
- Authorization: Required (JWT in "Authorization" header)
- Authorization Level: Logged In
- Description: Registers a logged in user for an event by its ID.
- Request Body:
{ }
- Response:
{ "message": "Successfully registered for event" }
- URL:
/events/{id}/register
- Method:
DELETE
- Authorization: Required (JWT in "Authorization" header)
- Authorization Level: Logged In
- Description: Cancels the registration of a logged in user for an event by its ID.
- Response:
{ "message": "Successfully cancelled registration for event" }
- URL:
/events/{id}/register
- Method:
GET
- Authorization: Required (JWT in "Authorization" header)
- Authorization Level: Logged In, Creator Only
- Description: Retrieves all registered users for an event by its ID.
- Response:
{ "registrations": [ { "email": "[email protected]" }, ... ] }
- Clone the repository:
git clone https://github.com/chriskoorzen/go-rest-events.git
- Navigate to the project directory:
cd go-rest-events
- Build and run the application:
go build ./go-rest-events
- The API will be available at
http://localhost:8080
.