Skip to content

mdombrov-33/gin-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gin REST API

This project is a REST API built with the Gin framework in Go. It provides user and event management functionalities, including user registration, login, event creation, updating, deletion, and user registration for events.

Features

  • User Management:

    • User Signup
    • User Login
    • Password Hashing and Verification
  • Event Management:

    • Create Event
    • Update Event
    • Delete Event
    • Register for Event
  • Database:

    • SQLite database for storing user and event data
    • Write-Ahead Logging (WAL) mode for better concurrency
  • Security:

    • Password hashing using Argon2
    • Authentication middleware for protected routes

Getting Started

Prerequisites

  • Go 1.16 or higher
  • SQLite3

Installation

  1. Clone the repository:
git clone https://github.com/mdombrov-33/gin-rest-api.git
cd gin-rest-api
  1. Install dependencies:
go mod tidy
  1. Build the application:
go build -o gin-rest-api
  1. Run the application:
./gin-rest-api

API Endpoints

User Management

  • Signup: POST /signup:

Request body:

{
"email": "testuser@gmail.com",
"password": "test"
}

Response: 201 Created

{
  "message": "User Created!"
}
  • Login: POST /login:

Request body:

{
   "email": "testuser@gmail.com",
   "password": "test"
}

Response: 200 OK

{
  "message": "Login successful!",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3R1c2VyQGdtYWlsLmNvbSIsImV4cCI6MTczMDE4NjYzMSwidXNlcklkIjo1fQ.aEZHPT_HdpHf6S3I-oIkgfHLYHUYFrBvXFlQQDaMMVA"
}

Event Management

  • Create Event: POST /events

Request body:

authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3R1c2VyQGdtYWlsLmNvbSIsImV4cCI6MTczMDE4NjYzMSwidXNlcklkIjo1fQ.aEZHPT_HdpHf6S3I-oIkgfHLYHUYFrBvXFlQQDaMMVA

{
"title": "Event Title",
"description": "Event Description",
"location": "Event Location",
"dateTime": "2025-12-31T23:59:59Z"
}

Response: 201 Created

{
"event": {
"ID": 1,
"Title": "Event Title",
"Description": "Event Description",
"Location": "Event Location",
"DateTime": "2025-12-31T23:59:59Z",
"UserID": 1
},
"message": "Event Created!"
}
  • Get All Events: GET /events

Response: 200 OK

[
{
"ID": 1,
"Title": "Event Title",
"Description": "Event Description",
"Location": "Event Location",
"DateTime": "2025-12-31T23:59:59Z",
"UserID": 1
  }
]
  • Get Single Event: GET /events/:id

Response: 200 OK

{
"ID": 1,
"Title": "Event Title",
"Description": "Event Description",
"Location": "Event Location",
"DateTime": "2025-12-31T23:59:59Z",
"UserID": 1
}
  • Update Event: PUT /events/:id

Request Body:

authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3R1c2VyQGdtYWlsLmNvbSIsImV4cCI6MTczMDE4NjYzMSwidXNlcklkIjo1fQ.aEZHPT_HdpHf6S3I-oIkgfHLYHUYFrBvXFlQQDaMMVA

{
"title": "New Event Title",
"description": "New Event Description",
"location": "New Event Location",
"dateTime": "2065-12-31T23:59:59Z"
}

Response: 200 OK

{
"event": {
"ID": 1,
"Title": "New Event Title",
"Description": "New Event Description",
"Location": "New Event Location",
"DateTime": "2065-12-31T23:59:59Z",
"UserID": 1
},
"message": "Event updated!"
}
  • Delete Event: DELETE /events/:id

Request Body:

authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3R1c2VyQGdtYWlsLmNvbSIsImV4cCI6MTczMDE4NjYzMSwidXNlcklkIjo1fQ.aEZHPT_HdpHf6S3I-oIkgfHLYHUYFrBvXFlQQDaMMVA

Response: 200 OK

{
"event": {
"ID": 1,
"Title": "Event Title",
"Description": "Event Description",
"Location": "Event Location",
"DateTime": "2025-12-31T23:59:59Z",
"UserID": 1
},
"message": "Event deleted!"
}
  • Register for Event: POST /events/:id/register

Request Body:

authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3R1c2VyQGdtYWlsLmNvbSIsImV4cCI6MTczMDE4NjYzMSwidXNlcklkIjo1fQ.aEZHPT_HdpHf6S3I-oIkgfHLYHUYFrBvXFlQQDaMMVA

Response: 201 Created

{
"message": "Successfully registered for the event"
}
  • Cancel Registration for Event: DELETE /events/:id/register

Request body:

authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3R1c2VyQGdtYWlsLmNvbSIsImV4cCI6MTczMDE4NjYzMSwidXNlcklkIjo1fQ.aEZHPT_HdpHf6S3I-oIkgfHLYHUYFrBvXFlQQDaMMVA

Response: 200 OK

{
"message": "Successfully canceled registration"
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages