GnarlyLasagna / go-events-api

This is a REST API built using Go and SQLite3.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Events Rest-API

Quick Start

Install Dependencies using go get:

$ go get

Then run the API on Port:8080 :

$ go run .

API Details

  • These libraries are the most important that allowed me to build this project.
  • Gin library which was very helpful for HTTP request routing.
  • jwt-go for Auth tokens in requests to verify users.
  • bcrypt for encrypting and decrypting passwords stored in the SQL DataBase.
  • And go-sqlite3 for running the SQL server.

API Routes

GET Requests

- /api/events

  • Description: Get a list of available events
  • Example Request:
    GET http://localhost:8080/events
  • Example Response:
    [
    {
        "ID": 1,
        "Name": "Test event",
        "Description": "Test event!!!",
        "Location": "A test location",
        "DateTime": "2025-01-01T15:30:00Z",
        "UserID": 1
    },
    {
        "ID": 2,
        "Name": "Second Test event",
        "Description": "A Second Test event!!!",
        "Location": "Another test location",
        "DateTime": "2025-02-01T15:30:00Z",
        "UserID": 1
    }
    ]

- /api/events/<id>

  • Description: Get an event by specific ID
  • Example Request:
    GET http://localhost:8080/events/21
  • Example Response:
    {
    "ID": 1,
    "Name": "Test event",
    "Description": "Test event!!!",
    "Location": "A test location",
    "DateTime": "2025-01-01T15:30:00Z",
    "UserID": 1
    }

POST Requests

- /api/events

  • Description: Create bookable event
  • (Auth Required)
    • Example Request:
      POST http://localhost:8080/events
      content-type: application/json
      authorization: <JWT TOKEN>
      
      {
      "name": "Test event",
      "description": "Test event!!!",
      "location": "A test location",
      "dateTime": "2025-01-01T15:30:00.000Z"
      }
    • Example Response:
      {
      "event": {
          "ID": 1,
          "Name": "Test event",
          "Description": "Test event!!!",
          "Location": "A test location",
          "DateTime": "2025-01-01T15:30:00Z",
          "UserID": 1
      },
      "message": "Event created!"
      }

- /api/signup

  • Description: Create a new user
  • Example Request:
    POST http://localhost:8080/signup
    content-type: application/json
    
    {
    "email": "test2@example.com",
    "password": "test"
    }
  • Example Response:
    {"message":"User created successfully"}

- /api/login

  • Description: Sign in and Authenticate user
  • (Returns Auth Token)
    • Example Request:
      POST http://localhost:8080/login
      content-type: application/json
      
      {
      "email": "test2@example.com",
      "password": "test"
      }
    • Example Response:
      {
      "message": "Login successful!",
      "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InRlc3QyQGV4YW1wbGUuY29tIiwiZXhwIjoxNzA2NTcyMjQzLCJ1c2VySWQiOjF9.RYcqW9laXx91E-0JNqPtyngLdYK3P9O8CvC7YgqrSVk"
      }

- /api/events/<id>/register

  • Description: Register the user for an Event
  • (Auth Required)
    • Example Request:
      POST http://localhost:8080/events/21/register
      authorization: <JWT TOKEN>
    • Example Response:
      {
      "message": "Registered!"
      }

PUT Requests

- /api/events/<id>

  • Description: Update an existing Event
  • (Auth Required) (Only by Creator)
    • Example Request:
      PUT http://localhost:8080/events/21
      content-type: application/json
      authorization: <JWT TOKEN>
      
      {
      "name": "Updated test event",
      "description": "A test event",
      "location": "Test location (Updated!)",
      "dateTime": "2025-01-01T15:30:00Z"
      }
    • Example Response:
      {
      "message": "Event updated successfully!"
      }

DELETE Requests

- /api/events/<id>

  • Description: Delete an Event by ID
  • (Auth Required) (Only by Creator)
    • Example Request:
      DELETE http://localhost:8080/events/21
      authorization: <JWT TOKEN>
    • Example Response:
      {
      "message": "Event deleted successfully!"
      }

- /api/events/<id>/register

  • Description: Delete a registration for an Event
  • (Auth Required)
    • Example Request:
      DELETE http://localhost:8080/events/21/register
      authorization: <JWT TOKEN>
    • Example Response:
      {
      "message": "Cancelled!"
      }

About

This is a REST API built using Go and SQLite3.


Languages

Language:Go 100.0%