Hi Please help me out. I want to understand how to build a web service api.
I'm a bit lost with terminology. Do I have the following right.
Restful = returns data in json format and there are no other speciffics that makes it a restfull web service ?
SOAP = same as above but instead of json it returns the format in XML , the only specifics that makes it a valid SOAP envelope is in the header ?
I haven't touched on SOAP yet , I'm starting with json due to trend people seem to prefer restful ?
I'm using a purchase order document as my example.
Its has a header, detail and ship to location and i created 3 classes for the header,detail and ship to that will hold the values of each field.
See below. (please focus on the the method i used to return the data and ignore the un-escapped security risks)
My Biggest question is the detail part of the deader which is a nested array of data with-in the header
If you look at the last 2 object properties of the header class.
Is the above the correct way of using it ? Not I have to work backward by returning the sub arrays first before the root in order to make
php's json_encode() to parse it correctly.
Below is the results,
Am I doing anything wrong or is it the correct way of creating a web service ?

I'm a bit lost with terminology. Do I have the following right.
Restful = returns data in json format and there are no other speciffics that makes it a restfull web service ?
SOAP = same as above but instead of json it returns the format in XML , the only specifics that makes it a valid SOAP envelope is in the header ?
I haven't touched on SOAP yet , I'm starting with json due to trend people seem to prefer restful ?
I'm using a purchase order document as my example.
Its has a header, detail and ship to location and i created 3 classes for the header,detail and ship to that will hold the values of each field.
See below. (please focus on the the method i used to return the data and ignore the un-escapped security risks)
My Biggest question is the detail part of the deader which is a nested array of data with-in the header
If you look at the last 2 object properties of the header class.
Code:
public $PO_DETAIL;
public $PO_SHIP_TO;
Is the above the correct way of using it ? Not I have to work backward by returning the sub arrays first before the root in order to make
php's json_encode() to parse it correctly.
Code:
<?php
/*
PHP JSON Web-Service response tutorial
*/
if(!empty($_GET["username"])){$Username = $_GET["username"];}else{$Username='NONE';}
if(!empty($_GET["password"])){$Passowrd = $_GET["password"];}else{$Passowrd='NONE';}
if($Username=='username' && $Passowrd=='password')
{
$PO_Detail[0] = new po_detail_data();
$PO_Detail[0]->ITEM_NUMBER="0000001A12dC";
$PO_Detail[0]->ITEM_DESC="NEMA 17 Stepper motor";
$PO_Detail[0]->QTY_ORDERED="12";
$PO_Detail[0]->UNIT_PRICE="75235.00";
$PO_Detail[1] = new po_detail_data();
$PO_Detail[1]->ITEM_NUMBER="0000202B13dC";
$PO_Detail[1]->ITEM_DESC="NEMA 17 Stepper Driver";
$PO_Detail[1]->QTY_ORDERED="12";
$PO_Detail[1]->UNIT_PRICE="75235.00";
$PO_SHIP_TO = new po_ship_to();
$PO_SHIP_TO->ADDR_NAME='Company on the moon';
$PO_SHIP_TO->ADDR_COUNTRY='Moon';
$PO_SHIP_TO->ADDR_STATE='Darkside';
$PO_SHIP_TO->ADDR_CITY='Centurion';
$PO_SHIP_TO->ADDR_SUBURB='3 Craters';
$PO_SHIP_TO->ADDR_CONTACT_NAME='Sarah Kerrigan';
$PO_SHIP_TO->ADDR_CONTACT_TEL1='000 000 0000';
$PO_SHIP_TO->ADDR_CONTACT_TEL2='000 000 0000';
$PO_SHIP_TO->ADDR_1='Base 1';
$PO_SHIP_TO->ADDR_2='Pod2';
$PO_SHIP_TO->ADDR_3='';
$PO_head = new po_header_data();
$PO_head->PO_NUMBER="PO0023456";
$PO_head->PO_REFERENCE="Test Ref";
$PO_head->PO_DESC="Test Desc";
$PO_head->POST_DATE="2018-10-12";
$PO_head->PO_DETAIL=$PO_Detail;
$PO_head->PO_SHIP_TO=$PO_SHIP_TO;
header('Content-type: application/json');
echo json_encode($PO_head);
}
else
{
echo 'Username or password is incorrect';
}
class po_header_data
{
public $PO_NUMBER;
public $PO_REFERENCE;
public $PO_DESC;
public $POST_DATE;
public $PO_DETAIL;
public $PO_SHIP_TO;
}
class po_detail_data
{
public $ITEM_NUMBER;
public $ITEM_DESC;
public $QTY_ORDERED;
public $UNIT_PRICE;
}
class po_ship_to
{
public $ADDR_NAME;
public $ADDR_COUNTRY;
public $ADDR_STATE;
public $ADDR_CITY;
public $ADDR_SUBURB;
public $ADDR_1;
public $ADDR_2;
public $ADDR_3;
public $ADDR_CONTACT_NAME;
public $ADDR_CONTACT_TEL1;
public $ADDR_CONTACT_TEL2;
}
?>
Below is the results,
Am I doing anything wrong or is it the correct way of creating a web service ?





