Simple Go backend for the svelte ecommerce frontend
Run the code directly if you have go installed on the machine
i. Clone Repository and change directory into the folder
$ git clone https://github.com/wesleymutwiri/authvice.git && cd authvice
ii. Build the application into a single binary via:
$ go build -o main .
iii. Create a sample .env file with your postgres configuration(Dockerfile coming soon to save you the trouble)
$ cp .env.example .env
iv. Run the executable go file by:
$ ./main
The REST API to the gocommerce app is described below.
GET /users
curl -i -H 'Accept: application/json' https://localhost:8080/users/
HTTP/1.1 200 OK
Date: Thu, 24 Feb 2011 12:36:30 GMT
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 2
[]
POST /users
curl -i -H 'Accept: application/json' --data '{"username": "aa","email": "[email protected]","password": "password"}' https://localhost:8080/users
HTTP/1.1 201 Created
Date: Thu, 24 Feb 2011 12:36:30 GMT
Status: 201 Created
Connection: close
Content-Type: application/json
Location: /thing/1
Content-Length: 36
{
"id":1,"username":"aa",
"email":"[email protected]",
"created_at":"2020-11-10T20:57:31.763849+03:00",
"updated_at":"2020-11-10T20:57:31.763849+03:00"
}
GET /users/id
curl -i -H 'Accept: application/json' https://localhost:8080/users/1
HTTP/1.1 200 OK
Date: Thu, 24 Feb 2011 12:36:30 GMT
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 36
{
"id":1,
"username":"wes",
"email":"[email protected]",
"created_at":"2020-11-10T20:57:31.763849+03:00",
"updated_at":"2020-11-10T20:57:31.763849+03:00"
}
GET /users/id
curl -i -H 'Accept: application/json' https://localhost:8080/users/9999
HTTP/1.1 404 Not Found
Date: Thu, 24 Feb 2011 12:36:30 GMT
Status: 404 Not Found
Connection: close
Content-Type: application/json
Content-Length: 35
{"error":"record not found"}
GET /products
curl -i -H 'Accept: application/json' https://localhost:8080/products/
HTTP/1.1 200 OK
Date: Thu, 24 Feb 2011 12:36:30 GMT
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 2
[]
POST /products
curl -i -H 'Accept: application/json' --data '{"name": "socks","description": "Some socks over here that do well","regular_price": 100,"discount_price": 30"quantity": 2,"number_items": 10}' https://localhost:8080/products
HTTP/1.1 201 Created
Date: Thu, 24 Feb 2011 12:36:30 GMT
Status: 201 Created
Connection: close
Content-Type: application/json
Location: /thing/1
Content-Length: 36
{
"id":1,
"name":"socks",
"description":"Some socks over here that do well",
"regular_price":100,
"discount_price":30,
"quantity":2,
"number_items":10,
"created_at":"2021-01-03T22:45:29.737201+03:00",
"updated_at":"2021-01-03T22:45:29.737201+03:00"
}
GET /products/id
curl -i -H 'Accept: application/json' https://localhost:8080/products/1
HTTP/1.1 200 OK
Date: Thu, 24 Feb 2011 12:36:30 GMT
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 36
{
"id":1,
"name":"socks",
"description":"Some socks over here that do well",
"regular_price":100,
"discount_price":30,
"quantity":2,
"number_items":10,
"created_at":"2021-01-03T22:45:29.737201+03:00",
"updated_at":"2021-01-03T22:45:29.737201+03:00"
}
GET /products/id
curl -i -H 'Accept: application/json' https://localhost:8080/products/9999
HTTP/1.1 404 Not Found
Date: Thu, 24 Feb 2011 12:36:30 GMT
Status: 404 Not Found
Connection: close
Content-Type: application/json
Content-Length: 35
{"error":"record not found"}