Skip to content
Simple API demo for product listing
PHP Dockerfile
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
db
public
src
views
.gitignore
Dockerfile
Procfile
composer.json
composer.lock
readme.md

readme.md

Simple Product API for Belanja

Requirements

  • Git
  • Composer
  • PHP 7 or latest with SQLite PDO
  • Docker (Optional for Build Image)

Installation

  • Clone this repository using git
git clone git@github.com:andhikayuana/belanja-api.git
  • Install dependencies using composer
cd belanja-api
composer install

Running

To run this API using this command

cd belanja-api
php -S localhost:3000 -t public

Build Image

You can build the docker image by using below command

cd belanja-api
docker build -t api.belanja .

or you can just pull docker image in from docker hub

docker pull andhikayuana/api-belanja

Now, you can access using Postman http://localhost:3000 and see

{
    "code": 200,
    "msg": "Success",
    "data": {
        "name": "Belanja API Demo",
        "version": "1.0.0"
    }
}

How to use

  • BASE_URL=http://localhost:3000
  • GET /products get all products

response example

{
    "code": 200,
    "msg": "Success",
    "data": [
        {
            "id": 1,
            "name": "Sandal Mahal",
            "price": 5000000,
            "image": "https://anu.com/images/sandal-mahal.jpg"
        },
        {
            "id": 2,
            "name": "Baju Mahal",
            "price": 8000000,
            "image": "https://anu.com/images/baju-mahal.jpg"
        }
    ]
}
  • GET /products/{id} get product by id

response example

{
    "code": 200,
    "msg": "Success",
    "data": {
        "id": 1,
        "name": "Sandal Mahal",
        "price": 5000000,
        "image": "https://anu.com/sandal-mahal.jpg"
    }
}
  • POST /products insert product data

request example

{
	"name": "Sepatu Mahal Banget",
	"price": 6000000,
	"image": "http://anu.com/images/weird-shoes-3-1.jpg"
}

response example

{
    "code": 200,
    "msg": "Success",
    "data": {
        "name": "Sepatu Mahal Banget",
        "price": 6000000,
        "image": "http://anu.com/images/weird-shoes-3-1.jpg",
        "id": 4
    }
}
  • PUT /products/{id} update product data

request example

{
	"name": "Sepatu Mahal wkwk",
	"price": 2500000,
	"image": "https://anu.com/weird-and-funny-shoes02.jpg"
}

response example

{
    "code": 200,
    "msg": "Success",
    "data": {
        "id": 4,
        "name": "Sepatu Mahal wkwk",
        "price": 2500000,
        "image": "https://anu.com/weird-and-funny-shoes02.jpg"
    }
}
  • DELETE /products/{id} delete product data

response example

{
    "code": 200,
    "msg": "Success",
    "data": []
}

Show QR Code for scanning the product

  • GET /products/qr-code show qr code to get product data
You can’t perform that action at this time.