Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andhikayuana/belanja-api
Simple API demo for product listing
https://github.com/andhikayuana/belanja-api
api belanja crud crud-api php php7 psr4
Last synced: about 1 month ago
JSON representation
Simple API demo for product listing
- Host: GitHub
- URL: https://github.com/andhikayuana/belanja-api
- Owner: andhikayuana
- Created: 2018-05-20T14:08:29.000Z (over 6 years ago)
- Default Branch: develop
- Last Pushed: 2024-01-21T15:19:13.000Z (11 months ago)
- Last Synced: 2024-01-21T16:28:59.015Z (11 months ago)
- Topics: api, belanja, crud, crud-api, php, php7, psr4
- Language: PHP
- Homepage: https://belanja-api.herokuapp.com
- Size: 20.5 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## 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`
```bash
git clone [email protected]:andhikayuana/belanja-api.git
```* Install dependencies using `composer`
```bash
cd belanja-api
composer install
```### Running
To run this API using this command
```bash
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
```json
{
"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
```json
{
"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
```json
{
"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
```json
{
"name": "Sepatu Mahal Banget",
"price": 6000000,
"image": "http://anu.com/images/weird-shoes-3-1.jpg"
}
```response example
```json
{
"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
```json
{
"name": "Sepatu Mahal wkwk",
"price": 2500000,
"image": "https://anu.com/weird-and-funny-shoes02.jpg"
}
```response example
```json
{
"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
```json
{
"code": 200,
"msg": "Success",
"data": []
}
```### Show QR Code for scanning the product
* `GET` `/products/qr-code` _show qr code to get product data_