This is a small project to finalize my Golang course. This API handles events and users. Users can create events and events are asociated with a user. Only event owners can delete the event and to enable security the application uses JWT for authentication. Last but not least, as DB driver the application works with etcd.
First start the etcd container
docker compose up -dThen get the packages for Go
go mod tidythen you can start working with the endpoints.
This documentation provides a detailed overview of the API endpoints defined in the Postman collection. The API consists of two main sections: Events and Users. Each section contains various endpoints for performing CRUD (Create, Read, Update, Delete) operations.
The base URL for all API requests is:
http://{{server}}:{{port}}
{{server}}: Typically set tolocalhost.{{port}}: Typically set to8080.
Endpoint: POST /events
Adds a new event to the system.
Content-Type: application/jsonAuthorization: Bearer<JWT_TOKEN>
{
"name": "event name",
"location": "event location"
}curl -X POST http://localhost:8080/events \
-H "Content-Type: application/json" \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
-d '{
"name": "event name",
"location": "event location"
}'Endpoint: GET /events
Retrieves a list of all events.
curl -X GET http://localhost:8080/eventsEndpoint: GET /events/{id}
Retrieves a specific event by its ID.
id: The unique uuid identifier of the event (e.g.,62aca175-8945-4221-a2b3-52e6889eee23).
curl -X GET http://localhost:8080/events/f0f2ca84-b788-413c-85f5-714443c42379Endpoint: PUT /events/{id}
Updates an existing event.
id: The unique identifier of the event (e.g.,62aca175-8945-4221-a2b3-52e6889eee23).
Content-Type: application/json
{
"name": "event name",
"location": "event location"
}curl -X PUT http://localhost:8080/events/f0f2ca84-b788-413c-85f5-714443c42379 \
-H "Content-Type: application/json" \
-d '{
"name": "event name",
"location": "event location"
}'Endpoint: DELETE /events/{id}
Deletes a specific event by its ID.
id: The unique identifier of the event (e.g.,f0f2ca84-b788-413c-85f5-714443c42379).
Content-Type: application/jsonAuthorization: Bearer<JWT_TOKEN>
curl -X DELETE http://localhost:8080/events/f0f2ca84-b788-413c-85f5-714443c42379 \
-H "Content-Type: application/json" \
-H "Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."Endpoint: POST /signup
Registers a new user in the system.
Content-Type: application/json
{
"email": "[email protected]",
"password": "password123"
}curl -X POST http://localhost:8080/signup \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "password123"
}'Endpoint: POST /login
Authenticates a user and returns a JWT token.
Content-Type: application/json
{
"email": "[email protected]",
"password": "password123"
}curl -X POST http://localhost:8080/login \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "password"
}'- Replace placeholders like
{{server}},{{port}}, and<JWT_TOKEN>with actual values when making requests. - Ensure that the JWT token used in authorized requests is valid and not expired.
- The API uses JSON Web Tokens (JWT) for authentication, which are added to the
Authorizationheader as a Bearer token.
This documentation provides a clear and concise overview of the API's structure and usage. Developers can refer to this guide to understand how to interact with the API effectively.