Giter Club home page Giter Club logo

go-rest's Introduction

GO REST API

REST API written in GO.

Bare-bones REST API written in GO with a sqlite database and JWT Authentication. Allows signup, login, CRUD operations on events, registering and unregistering.

Install/Run

  1. Download the code
  2. Make sure you have GO installed on your system
  3. Run go run .

User Routes

Create User

Request

POST http://localhost:8080/signup
Content-Type: application/json

{
    "email": "[email protected]",
    "password": "password"
}

Response

HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
Date: Sat, 06 Jan 2024 15:06:28 GMT
Content-Length: 87
Connection: close

{
  "message": "User created",
  "user": {
    "Id": 1,
    "Email": "[email protected]",
    "Password": "password"
  }
}

Login

Request

POST http://localhost:8080/login
Content-Type: "application/json"
    
    {
        "email": "[email protected]",
        "password": "password"
    }

Response

HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
Date: Sat, 06 Jan 2024 15:07:19 GMT
Content-Length: 192
Connection: close

{
  "message": "Login successful",
  "token": "<token>"
}

Event Routes

Get Events

Request

GET http://localhost:8080/events

Response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Sat, 06 Jan 2024 15:10:44 GMT
Content-Length: 183
Connection: close

[
  {
    "Id": 1,
    "Name": "Test event",
    "Description": "A test event",
    "Location": "A test location",
    "DateTime": "2025-01-01T15:30:00Z",
    "UserId": 1,
    "Registrations": [
      {
        "Id": 1,
        "UserId": 1,
        "EventId": 1
      }
    ]
  }
]

Get Event by Id

Request

GET http://localhost:8080/events/1

Response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Sat, 06 Jan 2024 15:10:33 GMT
Content-Length: 181
Connection: close

{
  "Id": 1,
  "Name": "Test event",
  "Description": "A test event",
  "Location": "A test location",
  "DateTime": "2025-01-01T15:30:00Z",
  "UserId": 1,
  "Registrations": [
    {
      "Id": 1,
      "UserId": 1,
      "EventId": 1
    }
  ]
}

Create Event

Request

POST http://localhost:8080/events
Content-Type: application/json
Authorization: <token>

{
    "name" : "Test event",
    "description" : "A test event",
    "location": "A test location",
    "datetime" : "2025-01-01T15:30:00.000Z"
} 

Response

HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
Date: Sat, 06 Jan 2024 15:08:59 GMT
Content-Length: 188
Connection: close

{
  "event": {
    "Id": 1,
    "Name": "Test event",
    "Description": "A test event",
    "Location": "A test location",
    "DateTime": "2025-01-01T15:30:00Z",
    "UserId": 1,
    "Registrations": null
  },
  "message": "Event created"
}

Update Event

Note: Only the user who created the event can update it.

Request

PUT http://localhost:8080/events/1
content-type: application/json
Authorization: <token>

{
    "name": "Updated test event",
    "description": "Updated test event description",
    "datetime": "2025-01-01T15:30:00Z",
    "location": "Updated test event location"
}

Response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Sat, 06 Jan 2024 15:14:18 GMT
Content-Length: 226
Connection: close

{
  "event": {
    "Id": 1,
    "Name": "Updated test event",
    "Description": "Updated test event description",
    "Location": "Updated test event location",
    "DateTime": "2025-01-01T15:30:00Z",
    "UserId": 0,
    "Registrations": null
  },
  "message": "Event updated"
}

Delete Event

Note: Only the user who created the event can update it.

Request

DELETE http://localhost:8080/events/1
Authorization: <token>

Response

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Sat, 06 Jan 2024 15:19:17 GMT
Content-Length: 39
Connection: close

{
  "eventId": 1,
  "message": "Event deleted"
}

Register for Event

Request

POST http://localhost:8080/events/1/register
Authorization: <token>

Response

HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
Date: Sat, 06 Jan 2024 15:17:15 GMT
Content-Length: 277
Connection: close

{
  "event": {
    "Id": 1,
    "Name": "Updated test event",
    "Description": "Updated test event description",
    "Location": "Updated test event location",
    "DateTime": "2025-01-01T15:30:00Z",
    "UserId": 1,
    "Registrations": [
      {
        "Id": 0,
        "UserId": 1,
        "EventId": 1
      }
    ]
  },
  "message": "User registered to event",
  "userId": 1
}

Unregister from Event

Request

DELETE http://localhost:8080/events/1/register
Authorization: <token>

Response

HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
Date: Sat, 06 Jan 2024 15:17:41 GMT
Content-Length: 250
Connection: close

{
  "event": {
    "Id": 1,
    "Name": "Updated test event",
    "Description": "Updated test event description",
    "Location": "Updated test event location",
    "DateTime": "2025-01-01T15:30:00Z",
    "UserId": 1,
    "Registrations": []
  },
  "message": "User unregistered from event",
  "userId": 1
}

To-Do

  • Testing

go-rest's People

Contributors

criticalsession avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.