This is a Rest API built with Golang, Gin, Mongodb, using jwt-token to authorize routes
git clone https://github.com/charleyvibez/uninc.git
cp example.env .env
go get ./...
go run main.go
.
The REST API to the example app is described below.
POST /users/signup
http://localhost:3000/users/signup
{
"username": "your username",
"password": "your password"
}
HTTP/1.1 200 OK
Date: Thu, 25 Nov 2021 12:36:30 GMT+1
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 2
{
"InsertedID": "619f71f6b529c5890c0bb467"
}
POST /users/login
http://localhost:3000/users/login
{
"username": "your username",
"password": "your password"
}
HTTP/1.1 201 Created
Date: Thu, 25 Nov 2021 12:36:30 GMT+1
Status: 201 Created
Connection: close
Content-Type: application/json
Location: /thing/1
Content-Length: 36
{
"ID": "619f3d2509b5790471c4fc28",
"username": "username",
"Password": "hash_password",
"token": "your token",
"refresh_token": "refresh token",
"created_at": "2021-11-25T07:37:09Z",
"updated_at": "2021-11-25T10:50:58Z",
"user_id": "619f3d2509b5790471c4fc28"
}
POST /create/coupon
http://localhost:3000/create/coupon
token needs to be passed in the header
token: "your token"
{
"Title": "Test coupon",
"Description": "Testing out my create endpoint",
"DocumentUrl": "https://testing.com",
"CouponCode": "ever19"
}
HTTP/1.1 201 Created
Date: Thu, 25 Nov 2021 12:36:30 GMT+1
Status: 201 Created
Connection: close
Content-Type: application/json
Location: /thing/1
Content-Length: 36
[
{
"ID": "619f5f187f1b8dae8c989737",
"title": "Test coupon",
"description": "Testing out my create endpoint",
"documenturl": "https://testing.com",
"couponcode": "ever12",
"created_at": "2021-11-25T10:02:00Z",
"updated_at": "2021-11-25T10:02:00Z",
"coupon_id": "619f5f187f1b8dae8c989737"
},
{
"ID": "619f66bc5eb0ab1d0c933b67",
"title": "Test coupon",
"description": "Testing out my create endpoint",
"documenturl": "https://testing.com",
"couponcode": "ever15",
"created_at": "2021-11-25T10:34:36Z",
"updated_at": "2021-11-25T10:34:36Z",
"coupon_id": "619f66bc5eb0ab1d0c933b67"
},
{
"ID": "619f66c8f135b2f8507cb29e",
"title": "Test coupon",
"description": "Testing out my create endpoint",
"documenturl": "https://testing.com",
"couponcode": "ever19",
"created_at": "2021-11-25T10:34:48Z",
"updated_at": "2021-11-25T10:34:48Z",
"coupon_id": "619f66c8f135b2f8507cb29e"
}
]
GET /coupons
http://localhost:3000/coupons
token needs to be passed in the header
token: "your token"
HTTP/1.1 200 OK
Date: Thu, 25 Nov 2021 12:36:30 GMT+1
Status: 200 OK
Connection: close
Content-Type: application/json
Location: /thing/1
Content-Length: 36
[
{
"ID": "619f5f187f1b8dae8c989737",
"title": "Test coupon",
"description": "Testing out my create endpoint",
"documenturl": "https://testing.com",
"couponcode": "ever12",
"created_at": "2021-11-25T10:02:00Z",
"updated_at": "2021-11-25T10:02:00Z",
"coupon_id": "619f5f187f1b8dae8c989737"
},
{
"ID": "619f66bc5eb0ab1d0c933b67",
"title": "Test coupon",
"description": "Testing out my create endpoint",
"documenturl": "https://testing.com",
"couponcode": "ever15",
"created_at": "2021-11-25T10:34:36Z",
"updated_at": "2021-11-25T10:34:36Z",
"coupon_id": "619f66bc5eb0ab1d0c933b67"
},
{
"ID": "619f66c8f135b2f8507cb29e",
"title": "Test coupon",
"description": "Testing out my create endpoint",
"documenturl": "https://testing.com",
"couponcode": "ever19",
"created_at": "2021-11-25T10:34:48Z",
"updated_at": "2021-11-25T10:34:48Z",
"coupon_id": "619f66c8f135b2f8507cb29e"
}
]