Once Apache and MySQL is ready, deploy the site to localhost (or server) and update the values for following parameters in index.php.
$config = array(
/** MySQL database name */
'database_name' => '',
/** MySQL hostname */
'database_host' => '',
/** MySQL database username */
'database_user' => '',
/** MySQL database password */
'database_password' => '',
);
After setting values for the above parameters, visit the URL http://servername/phprestapi/config/install.php. install.php will create the database and tables.
If there is no database exists, install.php will create the database and tables. Otherwise, displays the message "Database exists!".
Method to create single product.
name (string) - Product name.
{
"name": "value"
}
Returns a product object if the call succeeded.
{
"status": 201,
"message": "New product was created.",
"data": {
"id": "1",
"name": "Product 1",
"created_date": "2019-10-16 15:30:17"
}
}
Error responses
- Product with same name exists
{
"status": 200,
"message": "Product already exist.",
"data": "Product 1"
}
- Invalid input parameters
{
"status": 400,
"message": "Unable to create product. Required data is incomplete.",
"data": null
}
Method to create single purchaser.
name (string) - Purchaser name.
{
"name": "value"
}
Returns a purchaser object if the call succeeded.
{
"status": 201,
"message": "New purchaser was created.",
"data": {
"id": "1",
"name": "Purchaser 1",
"created_date": "2019-10-16 15:50:28"
}
}
Error responses
- Purchaser with same name exists
{
"status": 200,
"message": "Purchaser already exist.",
"data": "Purchaser 1"
}
- Invalid input parameters
{
"status": 400,
"message": "Unable to create purchaser. Required data is incomplete.",
"data": null
}
Method to create single purchase.
purchaser_id (integer) - Purchaser ID. product_id (integer) - Product ID. purchase_timestamp (string) - Purchase time-stamp.
{
"purchaser_id": 1,
"product_id": 1,
"purchase_timestamp": "1570924800"
}
Returns a purchase object if the call succeeded.
{
"status": 201,
"message": "New purchase was created.",
"data": {
"id": "1",
"purchaser_id": "1",
"product_id": "1",
"purchase_timestamp": "1570924800",
"created_date": "2019-10-16 16:03:28"
}
}
Error responses
- Purchase already exists
{
"status": 200,
"message": "Purchase already exist.",
"data": null
}
- Invalid input parameters
{
"status": 400,
"message": "Unable to create purchase. Required data is incomplete.",
"data": null
}
- Invalid Purchaser ID
{
"status": 200,
"message": "Purchaser not found with id",
"data": 2
}
- Invalid Product ID
{
"status": 200,
"message": "Product not found with id",
"data": 2
}
Method to read all purchase records which matches the input parameters.
GET http://servername/phprestapi/purchaser/{purchaser_id}/product?start_date={$start_date}&end_date={$end_date}
purchaser_id (int) - As identifier that identifies the purchaser.
start_date (string) - From date in YYYY-MM-DD format. It is optional. end_date (string) - To date in YYYY-MM-DD format. It is optional.
Returns purchase records which matches the input parameters.
{
"purchases": [
{
"2019-10-16": [
{
"product": "Bus"
},
{
"product": "Car"
},
{
"product": "jeep"
},
{
"product": "Motor Cycle"
}
],
"2019-10-13": [
{
"product": "Product 1"
},
{
"product": "Product 2"
},
{
"product": "Product 3"
}
]
}
]
}
Error responses
- Purchase records does not exist for the purchaser
{
"status": 200,
"message": "No purchase(s) found which matches the given criteria.",
"data": null
}
- Purchase does not exist for the given purchaser ID
{
"status": 200,
"message": "Purchaser not found with id",
"data": 2
}
- Purchaser ID is invalid (for example 23XEX)
{
"status": 400,
"message": "Purchaser ID is invalid.",
"data": "23XEX"
}
- Start date is invalid (for example 2019-13-3)
{
"status": 400,
"message": "Start date is invalid.",
"data": "2019-13-3"
}
- End date is invalid (for example 2019-12-34)
{
"status": 400,
"message": "End date is invalid.",
"data": "2019-12-34"
}
- Start date is greater than End date is invalid
{
"status": 400,
"message": "Start date is greater than end date.",
"data": {
"start_date": "2019-12-3",
"end_date": "2019-09-20"
}
}