It is an API helps you crawl data from https://shopee.vn/ about brands & products and save them to database which you can access later by also this one.
- Installation
- Usage
- Test
- Route Details
Fistly, we have to care about database migration. Supposed you're a MySQL user then:
migrate -database "mysql://username:password@tcp(yourhost:port)/databasename" -path migrations up
Folder migrations was prepared for purposes that you can easily up and down version of your database.
Lastly, you need to config database in env\database.env. Here is an example:
DATABASE_CONFIGURED = "YES"
DATABASE_USERNAME = "MY_USERNAME"
DATABASE_PASSWORD = "MY_PASSWORD"
DATABASE_HOST = "LOCALHOST"
DATABASE_PORT = "3306"
DATABASE_MAINDATABASENAME = "MAIN"
DATABASE_TESTDATABASENAME = "TEST"
Run your local server:
go run .
Result should be appeared:
yyyy/mm/dd hh:mm:ss Hosting: Local server: localhost:8080
Running port is changeable in env/server.env.
SERVER_PORT = "8080"
Use the following commands:
go test github.com/dee-ex/shopee_crawler_api/modules/brands
go test github.com/dee-ex/shopee_crawler_api/modules/products
Crawl all brands from https://shopee.vn/mall/brands and return as JSON.
/jobs/trigger/crawl_brands
Crawl all products of all brands from https://shopee.vn/each_brand_username and return as JSON (maximum return is 1000).
This process can be adjusted by query parameters.
/jobs/trigger/crawl_products?limit=X&from=Y&to=Z
Crawl all products of a specific brand username.
/jobs/trigger/crawl_products/{brand_username}
/brands
Create a new brand from data containing in body of request, save it to database and return as JSON.
{
"Shopid": 999999,
"Username": "testusername",
"BrandName": "testbrandname",
"Logo": "testlogo"
}
/brands
Get all brands and return as JSON.
/brands/{brand_id}
Get detail a brand by ID and return as JSON.
/brands/{brand_id}
Update a brand by ID. Updated data containing in body of request. Arguments are not required.
{
"BrandName": "updatebrandname",
"Logo": "testlogo"
}
/brands/{brand_id}
Delete a brand by ID.
/brands/{brand_id}/products
Get all products of a specific brand and return as JSON.
/products
Create a new product from data containing in body of request, save it to database and return as JSON.
{
"Shopid": 999999
"Itemid": 999998
"PriceMax": 999997
"PriceMin": 999996
"Name": "testname"
"Images": "testimage"
"HistoricalSold": 999995
"Rating": "testrating"
}
/products
Get all products and return as JSON.
/products/{product_id}
Get detail a product by ID and return as JSON.
/products/{product_id}
Update a product by ID. Updated data containing in body of request. Arguments are not required.
{
"Shopid": 999994
"PriceMax": 999993
"PriceMin": 999992
"Name": "updatename"
"Images": "updateimages"
"HistoricalSold": 999991
"Rating": "updaterating"
}
/products/{product_id}
Delete a product by ID.