- get product/category using
GET
- list products/categories using
GET
- create product/category with
POST
- update product/category using
PATCH
- listing supports pagination with page/per_page and order by asc/desc
POST
,DELETE
andUPDATE
require authorization. Just use username and pass from basicAuth used inside the server initialization.
- $
go get github.com/nmakro/best-price-api
Or if you prefer to git clone and manually install the project dependencies:
- $
git clone https://github.com/nmakro/best-price-api.git
Default configuration expects a running instance of mySQL running on port 3306
. You can change that to match your setup.
Import the example dump file or create a new db named best_price
with a user name best-price and password 123
.
$ go run main.go
$ curl -i "http://localhost:3000/best-price-api/v1/products/25"
HTTP/1.1 200 OK Date: Thu, 30 Apr 2020 10:20:06 GMT Content-Type: application/json Content-Length: 191
{
"id": 25,
"category_id": 5,
"title": "title 24",
"image_url": "",
"price": 72,
"description": "description 24",
"deleted_at": null,
"created_at": "2020-04-30T10:16:34Z",
"updated_at": "2020-04-30T10:16:34Z"
}
$ curl -i "http://localhost:3000/best-price-api/v1/products?per_page=4&page=1&sort=price:desc"
HTTP/1.1 200 OK
Date: Thu, 30 Apr 2020 10:29:11 GMT
Content-Type: application/json
Content-Length: 896
{
"_meta": {
"total_records": 200,
"total_pages": 50,
"per_page": 4,
"page": 1,
"prev_page": 1,
"next_page": 2
},
"products": [
{
"id": 200,
"category_id": 5,
"title": "title 199",
"image_url": "",
"price": 597,
"description": "description 199",
"deleted_at": null,
"created_at": "2020-04-30T11:36:28Z",
"updated_at": "2020-04-30T11:36:28Z"
},
{
"id": 199,
"category_id": 4,
"title": "title 198",
"image_url": "",
"price": 594,
"description": "description 198",
"deleted_at": null,
"created_at": "2020-04-30T11:36:28Z",
"updated_at": "2020-04-30T11:36:28Z"
},
{
"id": 198,
"category_id": 3,
"title": "title 197",
"image_url": "",
"price": 591,
"description": "description 197",
"deleted_at": null,
"created_at": "2020-04-30T11:36:28Z",
"updated_at": "2020-04-30T11:36:28Z"
},
{
"id": 197,
"category_id": 2,
"title": "title 196",
"image_url": "",
"price": 588,
"description": "description 196",
"deleted_at": null,
"created_at": "2020-04-30T11:36:28Z",
"updated_at": "2020-04-30T11:36:28Z"
}
]
}