Skip to content

yusuftalhaklc/go-fiber-gorm-pgsql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Fiber Example API

Go Fiber Example API is a RESTful API built using the Fiber web framework.

Installation

  1. Clone the repository:
git clone https://github.com/yusuftalhaklc/go-fiber-gorm-pgsql.git
  1. Navigate to the project directory:
cd go-fiber-gorm-pgsql
  1. Install the dependencies:
go mod tidy
  1. Start the API server:
go run main.go

It is currently running on localhost port 8080. Postman Collection

API Endpoints

Get All Users

  • Endpoint: /api/user
  • Method: GET
  • Authorization: Token
  • Description: Get all users.

Get Single User

  • Endpoint: /api/user/:id
  • Method: GET
  • Description: Get a single user by ID.

Login

  • Endpoint: /api/user/login
  • Method: POST
  • Description: Login.

Create User

  • Endpoint: /api/user
  • Method: POST
  • Description: Create a new user.

Update User

  • Endpoint: /api/user/:id
  • Method: PUT
  • Description: Update an existing user by ID.

Delete User

  • Endpoint: /api/user/:id
  • Method: DELETE
  • Description: Delete a user by ID.

Request Body and Response Examples

Create User

  • Request Body
{
    "username":"username",
    "email": "[email protected]",
    "password":"password123"
}
  • Response
{
    "data": [
        {
            "CreatedAt": "2023-06-26T11:46:46.46791+03:00",
            "UpdatedAt": "2023-06-26T11:46:46.46791+03:00",
            "DeletedAt": null,
            "ID": "f907c118-b2df-4920-9f04-6d13c96b355c",
            "username": "username",
            "email": "[email protected]",
            "password": "4ee1d94f2cc476688105a776dcc6d36c32ad00aa68b901baeff71b115676f45d"
        },
        {
            "CreatedAt": "2023-06-26T11:46:52.784047+03:00",
            "UpdatedAt": "2023-06-26T11:46:52.784047+03:00",
            "DeletedAt": null,
            "ID": "2e723e10-0a12-42ee-ac46-a9e268ebb66e",
            "username": "username2",
            "email": "[email protected]",
            "password": "7772448cf067ba366d81d3133feb61e449e65e3e6d516371cb2754e329c691b4"
        }
    ],
    "message": "Users Found",
    "status": "sucess"
}

Login

  • Request
POST /api/user/login
{
    "username":"username",
    "password":"password123"
}
  • Response
{
    "message": "Login succesfuly",
    "status": "success",
    "token": "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2ODc3ODE3MzksImlkIjoiZDk3MmE0NWEtNTNiZC00ODgwLTgwODktZDk1NDlkMzRhMzQ4IiwidXNlcm5hbWUiOiJ1c2VybmFtZTEyMyJ9.TjRCOKgQwGylLzOQ0kG3Qrk1ySOGZnGfa8SWPZHV-ZXNfucJcBV9Y4ysirFj2GXyxH1ybgZ6BME50E3HrsaPIA"
}

Get All User

  • Request
GET /api/users
  • Response
{
   "data": [
       {
           "CreatedAt": "2023-06-26T11:33:44.674928+03:00",
           "UpdatedAt": "2023-06-26T11:33:44.674928+03:00",
           "DeletedAt": null,
           "ID": "f907c118-b2df-4920-9f04-6d13c96b355c",
           "username": "username",
           "email": "[email protected]",
           "password": "4ee1d94f2cc476688105a776dcc6d36c32ad00aa68b901baeff71b115676f45d"
       }
   ],
   "message": "Users Found",
   "status": "sucess"
}

Get Single User

  • Request
GET /api/user/f907c118-b2df-4920-9f04-6d13c96b355c
  • Response
{
    "data": {
        "CreatedAt": "2023-06-26T11:33:44.674928+03:00",
        "UpdatedAt": "2023-06-26T11:33:44.674928+03:00",
        "DeletedAt": null,
        "ID": "f907c118-b2df-4920-9f04-6d13c96b355c",
        "username": "username",
        "email": "[email protected]",
        "password": "4ee1d94f2cc476688105a776dcc6d36c32ad00aa68b901baeff71b115676f45d"
    },
    "message": "User Found",
    "status": "success"
}

Update User

  • Request
PUT /api/user/f907c118-b2df-4920-9f04-6d13c96b355c
{
    "username" : "yusuftalhaklc"
}
  • Response
{
    "data": {
        "CreatedAt": "2023-06-26T11:33:44.674928+03:00",
        "UpdatedAt": "2023-06-26T11:39:07.7508237+03:00",
        "DeletedAt": null,
        "ID": "f907c118-b2df-4920-9f04-6d13c96b355c",
        "username": "yusuftalhaklc",
        "email": "[email protected]",
        "password": "4ee1d94f2cc476688105a776dcc6d36c32ad00aa68b901baeff71b115676f45d"
    },
    "message": "users Found",
    "status": "success"
}

Delete User

  • Request
DELETE /api/user/f907c118-b2df-4920-9f04-6d13c96b355c
  • Response
{
    "message": "User deleted",
    "status": "success"
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages