COMP519 Web Programming
Lecture 29: REST (Part 3)
Handouts
Ullrich Hustadt
Department of Computer Science
School of Electrical Engineering, Electronics, and Computer Science
University of Liverpool
Contents
1
PHP Implementation of a Web Service
Reminder
Useful PHP Functions
Rest.php Outline
Database Class
Address Class
Student Class
Sample REST function
2
Further Reading
COMP519 Web Programming Lecture 29 Slide L29 1
PHP Implementation of a Web Service Reminder
REST.php Motivation
In the last lecture, we have decided that we will deal with HTTP
requests to a web service
method https :/ / api . liv . ac . uk / v1 / resource ? query
by rewriting them to
method https :/ / api . liv . ac . uk / v1 / REST . php ? resource = re s ource
, & query
and we have devised a rewrite rule to achieve that
On the departmental systems,
the file REST.php will be in a directory
sgxyz /public_html/v1
the HTTP requests take the form
method https :// student . csc .liv . ac . uk /
sgxyz / v1 / resource ?
, query
and should be rewritten to
method https :// student . csc .liv . ac . uk /
sgxyz / v1 / REST . php ?
, resourc e = re s ource & query
COMP519 Web Programming Lecture 29 Slide L29 2
PHP Implementation of a Web Service Reminder
REST.php Motivation
We now have to implement REST.php
To simply the implementation we ignore the query parameter
REST.php has to ‘translate’ combinations of method and resource into
PHP function calls
Our implementation will make a decision on which PHP function to call
solely based on method but this is design choice
In a lot of situations more fine-grained decision making will be better
COMP519 Web Programming Lecture 29 Slide L29 3
PHP Implementation of a Web Service Useful PHP Functions
Useful PHP Functions
Exception([string
msg = ""[, int
code = 0]])
Creates an exception with exception message msg and exception
code cd
throw new Exceptio n ( ' Method Not Sup p orted ' , 405);
set_exception_handler( exceptionHandler )
Sets the default exception handler if an exception is not caught
within a try/catch block
exceptionHandler should be a function that accepts an
exception as an argument
Execution will stop after the call of exceptionHandler is completed
function exc e pti onH andl er ( $excpt ) {
echo " Uncaugh t exce p tion : ", $excpt -> getMes sage () , " \n ";
}
set _ex cep tio n_h and ler ( ' e xce pti o nHa ndl e r ' );
throw new Exceptio n ( ' Spur ious Ex ception ' );
echo "This code is not executed \n" ;
Uncaught excepti o n : Spurious Excepti on
COMP519 Web Programming Lecture 29 Slide L29 4
PHP Implementation of a Web Service Useful PHP Functions
Useful PHP Functions
php: //input
A read-only stream that allows to read raw data from the request body
$params = json _deco de ( f i le_ get _co nten ts ( ' php :// input ' ) ,
true );
Assuming that the request body contains JSON encoded data, read the whole of
php: //input and turn it into an associative array
explode(string
delimiter , string
str [, int
limit ])
Returns an array of strings, with a maximum of limit elements,
each of which is a substring of str formed by splitting it on boundaries
formed by the string delimiter
print_r ( explode ( ' / ' , ' this /is /a / fil epath ' ));
Array
( [0] => ' this ' [1] = > ' is ' [2] = > ' a ' [3] => ' f ilepath ' )
COMP519 Web Programming Lecture 29 Slide L29 5
PHP Implementation of a Web Service Useful PHP Functions
Useful PHP Functions
header(string
hStr [, bool
repl = TRUE[, int
httpRspCd ]])
Send a raw HTTP header including hStr and HTTP response
code httpRspCd
Replace a previous similar header if repl is TRUE , otherwise add
header ( ' Lo cation : http :// www . example . com / ' );
Add a location header to the response
Together with a response code 302 (REDIRECT) would tell a browers to visit the URL
indicated
header ( ' Content - Type : applica tion / json ' );
Add a header entry that indicates the request/response body contains JSON encoded
data
COMP519 Web Programming Lecture 29 Slide L29 6
PHP Implementation of a Web Service Useful PHP Functions
Useful PHP Functions
http_response_code([int
httpRspCd ])
Returns the previous HTTP response code and sets it to httpRspCd
if that argument is provided
Also sets the HTTP response text to a reason phrase provided
httpRspCd is a standard HTTP response code
htt p_r e spo nse _co de (201)
Sets the HTTP response code to 201 (CREATED)
COMP519 Web Programming Lecture 29 Slide L29 7
PHP Implementation of a Web Service Useful PHP Functions
Destructuring Assignments
PHP has several ways in which array elements can be assigned to several
variables in a single assignment
$ar1 = [ 2, 3, 5];
list ($x ,$y , $z ) = $ar1 ; // PHP 5. x or later
echo "\ $x = $x \ $y = $y \ $z = $z \ n" ;
$x = 2 $y = 3 $z = 5
[$u ,$v , $w] = $ar1 ; // PHP 7. x or later
echo "\ $u = $u \ $v = $v \ $w = $w \ n" ;
$u = 2 $v = 3 $w = 5
[0 = > $a ] = $ar1 ;
[ , $b , $c ] = $ar1 ;
echo "\ $a = $a \ $b = $b \ $c = $c \ n" ;
$a = 2 $b = 3 $c = 5
$ar2 = [ ' a ' => 2, ' b ' = > 3 , ' c ' = > 5];
[ ' a ' => $x , ' b ' => $y , ' c ' = > $z ] = $ar2 ; // PHP 7. x
echo "\ $x = $x \ $y = $y \ $z = $z \ n" ;
$x = 2 $y = 3 $z = 5
COMP519 Web Programming Lecture 29 Slide L29 8
PHP Implementation of a Web Service Rest.php Outline
REST.php : Outline (1)
<? php
requ i re_o nce ( ' Databa s e . php ' );
requ i re_o nce ( ' Model . php ' );
set _ex cep tio n_h and ler ( fu nction ($e ) {
$code = $e -> getCode () ?: 400;
header ( " Content - Type : app licat ion / json " , FALSE , $code );
echo j son_e ncode ([ " error " => $e -> getMess a ge ()]);
exit ;
});
// Open data b ase co nnect i on
$db = new Dat a base ();
// Retriev e inputs
$method = $_ SERVER [ ' REQUE ST_M ETHO D ' ];
$resou r ce = exp l o de ( ' / ' , $_RE Q UEST [ ' re source ' ]);
$inpu t Data = j son_ d ecod e ( file _get _co nte nts ( ' php :// input ' ) ,
TRUE );
COMP519 Web Programming Lecture 29 Slide L29 9
PHP Implementation of a Web Service Rest.php Outline
REST.php : Outline (2)
switch ( $method ) {
case ' GET ' :
[ $data , $ s tatus ] = r eadData ($db , $resour c e );
break ;
case ' PUT ' :
case ' POST ' :
[ $data , $ s tatus ] = c reate Data ($db , $method , $resource ,
$inpu t Data );
break ;
case ' DELETE ' :
[ $data , $ s tatus ] = d elete Data ($db , $resour c e );
break ;
default :
throw new Exceptio n ( ' Method Not Support e d ' , 405);
}
header ( " Content - Type : ap plica tion / json " , TRUE , $status );
echo $data ;
?>
COMP519 Web Programming Lecture 29 Slide L29 10
PHP Implementation of a Web Service Rest.php Outline
REST.php : POST Requests
We focus on POST HTTP requests that attempt to create a new student
using our web service
We allow such POST requests with minimum information consisting of
first name, surname and programme
POST /
sgxyz / v1 / students
Host : student . csc . liv . ac . uk
{" sname ":" Clay " ," fname ":" Cia " ," prog " :" CSMS " }
or more complete information with one or two addresses
POST /
sgxyz / v1 / students
Host : student . csc . liv . ac . uk
{" sname ":" Ady " , " fname ":" Ada " , " prog " :" CSMS ",
" tAddr ":{ " streetH N ": "1 Abby Road " , " city " : " Liver p ool ",
" p ostCode ": " L69 9 AA " , " country ":" UK "} ,
" pAddr ":{ " streetH N ": "9 Mort Street " , " city ":" Wigan ",
" p ostCode ": " WN2 4 TU " , " country ":" UK " }}
We assume that the web service will generate the student id
COMP519 Web Programming Lecture 29 Slide L29 11
PHP Implementation of a Web Service Database Class
Database.php : Database Class
class Database {
private $host = " studdb . csc . liv . ac . uk " ;
private $user = " sg f surn ";
private $pass w d = " ---- - --" ;
private $d atabas e = " sgfsurn ";
public $conn ;
public functi o n __c onstr uct () {
// we use the same options as usual
$opt = array ( ... ) ;
$this - > conn = null ;
try {
$this - > conn = new PDO ( ' mysql : host = ' . $this -> host . ' ;
, dbname = ' . $this - > databa s e . ' ; charset = utf8mb4 ' ,
, $this -> user , $this - > passwd , $opt ) ;
} catch ( PDOE xcep tion $e ) {
// If we can ' t get a da tabase connection , we return
// 503 Service U n avai l able
throw new Exceptio n ($e -> getM e ssage () ,503) ;
} } }
COMP519 Web Programming Lecture 29 Slide L29 12
PHP Implementation of a Web Service Database Class
Database.php : Database (1)
CREATE TABLE ` students ` (
` id ` int (10) NOT NULL ,
` sname ` varchar (50) DEFAULT NULL ,
` fname ` varchar (100) DEFAULT NULL ,
` prog ` char (4) DEFAULT NULL ,
` tAddrId ` m ediumi nt (9) DEFAU L T NULL ,
` pAddrId ` m ediumi nt (9) DEFAU L T NULL ,
PRIMARY KEY ( ` id ` ) ,
KEY ` termTime ` ( ` tAddrId ` ) ,
KEY ` permanent ` ( ` pAddrId ` ) ,
CONST R AINT ` fk1 ` FOREIGN KEY ( ` tAddrId ` )
REFER E NCES ` addresses ` ( ` id ` ) ,
CONST R AINT ` fk2 ` FOREIGN KEY ( ` pAddrId ` )
REFER E NCES ` addresses ` ( ` id ` )
) ENGINE = InnoDB ;
COMP519 Web Programming Lecture 29 Slide L29 13
PHP Implementation of a Web Service Database Class
Database.php : Database (2)
CREATE TABLE ` addresses ` (
` id ` med i umint (9) NOT NULL AUTO_INCREMEN T ,
` streetHN ` v archar (50) DEFAULT NULL ,
` city ` varchar (50) DEFAU L T NULL ,
` postCode ` v archar (8) DEFAULT NULL ,
` country ` varchar (50) DEFAULT NULL ,
` studentId ` int (10) NOT NULL ,
PRIMARY KEY ( ` id ` ) ,
CONST R AINT ` fk1 ` FOREIGN KEY ( ` studentId ` )
REFER E NCES ` students ` ( ` id ` )
ON DELETE CASCADE
) ENGINE = InnoDB ;
COMP519 Web Programming Lecture 29 Slide L29 14
PHP Implementation of a Web Service Address Class
Model.php : Address Class (1)
class Address {
// Private p roper t ies do not appear in the JSON encodin g
// of an object .
private $conn ;
private static $table = ' ad dresse s ' ;
private $id , $studen tId ;
private $parts = [ ' stree tHN ' , ' city ' , ' post C ode ' , ' country ' ];
// Address p roper t ies
public $streetHN , $city , $postCode , $country ;
// $_links will provide HATEOAS links
public $_links ;
COMP519 Web Programming Lecture 29 Slide L29 15
PHP Implementation of a Web Service Address Class
Model.php : Address Class (2)
// The cons t ruct or only sets the database connect ion and
// the student id of the st udent to whom the address
// belongs .
public functi o n __c onstr uct ($db , $sid ) {
$this - > conn = $db -> conn ;
$this - > st udentI d = $sid ;
}
// set () populate s the public prope r ties of an address ,
// values can be pr o vided as an array or an other object .
public functi o n set ( $source ) {
if ( is_obje c t ( $source ))
$source = ( array ) $source ;
foreach ( $source as $key => $value )
if ( in_array ( $key , $this -> parts ))
$this - > $key = $value ;
else
throw new Exceptio n (" $key not an at tribut e of
, address " ,400) ;
}
COMP519 Web Programming Lecture 29 Slide L29 16
PHP Implementation of a Web Service Address Class
Model.php : Address Class (3)
// HATEOS links are not stored in the database , but
// gener a ted using student Id $sid and address type
// $aType ( one of ' tAddr ' or ' pAddr ' ).
// $this -> _links is an array of objects . As PHP does
// not have literal objects , we cast arrays to create
// thos e o bjects .
public functi o n setLin ks ( $sid , $aType ) {
$this - > _links =
[( object )[ ' href ' => "/ students / $sid / addresse s / $aType " ,
' method ' => ' GET ' , ' rel ' = > ' self ' ],
( object )[ ' href ' = > " / students / $sid / a d dresse s / $aType " ,
' method ' => ' PATCH ' , ' rel ' => ' edit ' ] ,
( object )[ ' href ' = > " / students / $sid / a d dresse s / $aType " ,
' method ' => ' DELETE ' , ' rel ' => ' delete ' ]];
}
COMP519 Web Programming Lecture 29 Slide L29 17
PHP Implementation of a Web Service Address Class
Model.php : Address Class (4)
// stor e () stores an address in the database .
// In the process a unique id is generate d and returned .
public functi o n store () {
// An add r e ss belongs to a particu lar stu d e nt
$query = ' INSERT INTO ' . self :: $table .
' ( studentId , streetHN , city , postCode ,
country ) VALUES (? ,? ,? ,? ,?) ' );
$stmt = $this - > conn - > pr e pare ( $query ) ;
$stmt - > exe c u te ( arra y ( $this - > studentId , $this -> streetHN ,
$this - > city , $this -> postCode ,
$this - > cou n t ry ) ) ;
$this - > id = $this - > conn - > la stIn sert I d () ;
return $this -> id ;
}
COMP519 Web Programming Lecture 29 Slide L29 18
PHP Implementation of a Web Service Address Class
Model.php : Address Class (5)
// read () retri e ves an address from the database .
// $this -> id must have been set when read () is called .
public functi o n read ( $aType ) {
$query = ' SELECT * FROM ' . self :: $tabl e .
' WHERE id =: id ' ;
// Prepare and execut e stateme nt .
$stmt = $this - > conn - > p r epare ( $query ) ;
$stmt - > exe c u te ( arra y ( $this - > id ) ) ;
// Fetc h the single row that the query return s
$row = $stmt - > fetch () ;
// Transfe r database data into pr o perti es .
foreach ( $row as $key => $value )
$this - > $key = $value ;
// Set HATEOS links
$this - > se tLinks ( $this - > studentId , $aType ) ;
}
COMP519 Web Programming Lecture 29 Slide L29 19
PHP Implementation of a Web Service Address Class
Model.php : Address Class (6)
// Afte r we created a new Address object and filled its
// prop erties with user - provide d values , none of the
// prop erties should still have a NULL value
// ( though empty str i n gs are allowed ).
public functi o n valida te () {
foreach ($this -> parts as $key )
if ( is_null ($this -> $key ) )
return FALSE ;
return TRUE ;
}
// __to String () is called w h enever we need a string
// rep res e nta tion of an Address o b j e c t . We use its
// JSON r e pre sent atio n for that pur p o se .
public functi o n __t o Strin g () {
return jso n _enc ode ( $this ,
JSO N_U NES CAP ED_ UN I CO DE | J SO N _U NES CAP ED_ SLA SHE S );
}
COMP519 Web Programming Lecture 29 Slide L29 20
PHP Implementation of a Web Service Student Class
Model.php : Student Class (1)
class Student {
private $conn ;
private static $table = ' st u dents ' ;
private $parts = [ ' s t udentI d ' , ' sname ' , ' fname ' , ' prog ' ];
// Student P roper t ies
public $studentId , $sname , $fname , $prog ;
// $_links will provide HATEOAS links and a link
// to ad dresse s
public $_links ;
// $tAddrI d : Unique id of the term time address
// $pAddrI d : Unique id of the permanent address
// Thes e are pr i vate so that they do not occur
// in the JSON encodi n g of a St u d ent object
private $tAddrId , $ p AddrId ;
// The cons t ruct or only sets the database connect ion
public functi o n __c onstr uct ( $db ) { $this -> conn = $db -> conn
, ; }
COMP519 Web Programming Lecture 29 Slide L29 21
PHP Implementation of a Web Service Student Class
Model.php : Student Class (2)
// set () populate s the public prope r ties of a student ,
// values can be pr o vided as an array or an other object .
public functi o n set ( $source ) {
if ( is_obje c t ( $source ))
$source = ( array ) $source ;
foreach ( $source as $key => $value )
if ( in_array ( $key , $this -> parts ))
$this - > $key = $value ;
else
throw new Exceptio n (" $key not an at tribut e of
, student " ,400) ;
}
// We need a way to set the pr ivate pr o perti es
public functi o n set P rivat e ( $key , $value ) {
$this - > $key = $value ;
}
COMP519 Web Programming Lecture 29 Slide L29 22
PHP Implementation of a Web Service Student Class
Model.php : Student Class (3)
// HATEOS links are not stored in the database , but
// gener a ted using student Id $sid .
// $this -> _links is an array of objects .
public functi o n setLin ks ( $sid = NULL ) {
if ( $this -> studen t Id )
$sid = $this -> studen t Id ;
$this - > _links =
[( object )[ ' href ' => "/ students / $sid / addresse s " ,
' method ' => ' GET ' , ' rel ' = > ' add r esses ' ] ,
( object )[ ' href ' = > " / students / $sid " ,
' method ' => ' GET ' , ' rel ' = > ' self ' ],
( object )[ ' href ' = > " / students / $sid " ,
' method ' => ' PATCH ' , ' rel ' => ' edit ' ] ,
( object )[ ' href ' = > " / students / $sid " ,
' method ' => ' DELETE ' , ' rel ' => ' delete ' ]];
}
COMP519 Web Programming Lecture 29 Slide L29 23
PHP Implementation of a Web Service Student Class
Model.php : Student Class (4)
// stor e () stores a student in the database
public functi o n store () {
$query = ' INSERT INTO ' . self :: $table .
' ( studentId , sname , fname , prog , tAddrId ,
pAddrId ) VALUES (? ,? ,? ,? ,? ,?) ' ;
// Prepare s t atemen t
$stmt = $this - > conn - > pr e pare ( $query ) ;
$stmt - > exe c u te ( arra y ( $this - > studentID , $this -> sname ,
$this - > fname , $this -> prog ,
$this - > tAddrId , $this -> pAddrId ));
return $this -> studen tId ;
}
// __to String () is called w h enever we need a string
// rep res e nta tion of an Student o b j e c t .
public functi o n __t o Strin g () {
return jso n _enc ode ( $this ,
JSO N_U NES CAP ED_ UN I CO DE | J SO N _U NES CAP ED_ SLA SHE S );
}
COMP519 Web Programming Lecture 29 Slide L29 24
PHP Implementation of a Web Service Student Class
Model.php : Student Class (5)
// Clas s function that generat es a new student ID
// If there already s tudents in the database , take their
// highest s t udentI D plus 1, oth erwise use 2019000 001
public static functi on gen erate I D () {
$maxId A rr = $this -> conn - > query (" S E L E C T max ( id ) from
, student s ") -> fetch (PDO :: FETCH_N U M ) ;
$newId = min ( $maxIdA r r [0 ] +1 , 2019000 0 01) ;
return $newId ;
}
// Afte r we created a new Student object and filled its
// prop erties with user - provide d values , none of the
// prop erties should still have a NULL value
// ( though empty str i n gs are allowed ).
public functi o n valida te () {
foreach ($this -> parts as $key )
if ( is_null ($this -> $key ) )
return FALSE ;
return TRUE ;
}
COMP519 Web Programming Lecture 29 Slide L29 25
PHP Implementation of a Web Service Student Class
Model.php : Student Class (6)
// read () retri e ves a student from the database .
// $this -> studen t Id must have been set when read () is
// called .
public functi o n read () {
$query = ' SELECT * FROM ' . self :: $tabl e .
' WHERE studentI d =? ' ;
// Prepare and execut e stateme nt
$stmt = $this - > conn - > p r epare ( $query ) ;
$stmt - > exe c u te ( arra y ( $this - > studentI d )) ;
// Fetc h the single row that the query return s
$row = $stmt - > fetch () ;
// Transfe r database data into pr o perti es .
foreach ( $row as $key => $value )
$this - > $key = $value ;
// Set HATEOS links
$this - > se tLinks () ;
}
COMP519 Web Programming Lecture 29 Slide L29 26
PHP Implementation of a Web Service Sample REST function
Model.php : createData Function (1)
function create Data ($db , $method , $resource , $data ) {
if (( $method == ' POST ' ) &&
( count ( $res o urce ) == 1) &&
( $ resour ce [0] = ' s t udents ' )) {
return cre ateS tude nt ($db , $data );
} elseif (( $method == ' POST ' ) &&
( count ( $res o urce ) == 2) &&
( $ resour ce [0] = ' s t udents ' )) {
if ( preg_m atch ( ' /^\ d {10} $ / ' , $resource [1]) )
return cr eate Stu d ent WS ($db , $resourc e [1] , $data );
else
throw new Exceptio n ( ' Not a valid studen t Id ' , 400)
} else {
throw new Exceptio n ( ' Method Not Sup p orted ' , 405) ;
}
}
COMP519 Web Programming Lecture 29 Slide L29 27
PHP Implementation of a Web Service Sample REST function
Model.php : createStudent Function (1)
function crea teSt uden t ( $db ,& $data ) {
// We need to in s e r t up to three dat a base entr i e s
// Either all inse r tions should succeed or all sh o u l d fail
$db -> conn - > begi n Tra nsa c tio n () ;
$data [ ' stud entId ' ] = Student :: genera teId ( $db );
$std1 = new Student ($db - > conn ) ;
// If the JSON data con t ains a term time address , then
// try to create a cor r spon ding Address object , store it
// in the database , re member its prima r y key value
if ( arr a y_k ey_ e xis ts ( ' tAddr ' , $data ) )
$std1 - > setPriva te ( ' t A d drId ' ,
crea teAd dres s ($db , $data , ' tAddr ' ) );
// Do the same for a pe rmanen t address
if ( arr a y_k ey_ e xis ts ( ' pAddr ' , $data ) )
$std1 - > setPriva te ( ' p A d drId ' ,
crea teAd dres s ($db , $data , ' pAddr ' ) );
COMP519 Web Programming Lecture 29 Slide L29 28
PHP Implementation of a Web Service Sample REST function
Model.php : createStudent Function (2)
// Use the JSON data to set the public propert ies of
// the Student object
$std1 - > set ( $data );
if ( $std1 -> validate () ) {
// If sufficie nt data was provided , store the Student
// object in the database
$std1 - > store () ;
$db -> conn - > commit ();
$std1 - > se tLinks () ;
// Return the student object and res p onse code 201
return [ $std1 ,201];
} else {
// If insuff icie n t data was provided , roll every t hing
// back and create an error HTTP respone
$db -> conn - > ro llback ();
throw new Exceptio n (" Student data i ncomp lete " ,400) ;
} }
COMP519 Web Programming Lecture 29 Slide L29 29
PHP Implementation of a Web Service Sample REST function
Model.php : createAddress Function
// We want to use the createAdd r e ss f uncti on in two scenar ios :
// - $data is student data in cludi n g a ddress i nformati o n and
// student Id
// - $data is just ad dres s data and a stu dent Id is pr ovide d
// as a separat e a rgume nt
fun ction crea t e Address ( $db ,& $data , $aType , $sid = NULL ) {
if ( array_key_e x i s t s ( ' s tudent Id ' ,$data ))
$sid = $data [ ' s tudent Id ' ];
if ( array_key_e x i s t s ($aType , $da ta ))
$aData = $data [ $aTy pe ];
else
$aData = $data ;
$addr = new Addre ss ( $db -> conn , $sid );
$addr -> set ( $aData );
if ( $addr - > v alidat e ())
$addrId = $addr - > store ();
else
throw new Excep tion ( " A ddre ss $addrT ype i ncompl e te " ,400);
if ( array_key_e x i s t s ($aType , $da ta ))
unset ( $data [ $aType ]);
return $addrI d ;
}
COMP519 Web Programming Lecture 29 Slide L29 30
PHP Implementation of a Web Service Sample REST function
Model.php : To-do
To complete the implementation of our web service we need to
extend createData with further cases that deal with the creating of
addresses
we need to implement readData using the read methods we have already
defined in the Address and Student classes
we need to implement deleteData
We need to investigate how we can secure our web service
Cookie
Token (in query string or Authorization header)
COMP519 Web Programming Lecture 29 Slide L29 31
Further Reading
Revision and Further Reading
Digamber Rawat: Create Simple PHP 7|8 CRUD REST API with
MySQL & PHP PDO. positronx.io, 27 Nov 2020.
https://www.positronx.io/
create-simple-php-crud-rest-api-with-mysql-php-pdo/ ,
[accessed 25 Dec 2020]
Mike Dalisay: How To Create A Simple REST API in PHP? Step
By Step Guide! CodeOfaNinja, 29 Jun 2020.
https://codeofaninja.com/2017/02/
create-simple-rest-api-in-php.html [accessed 25 Dec 2020]
Brad Traversy: PHP REST API From Scratch. Traversy Media, 26
Jul 2018. https://www.youtube.com/playlist?list=
PLillGF-RfqbZ3_Xr8do7Q2R752xYrDRAo [accessed 25 Dec 2020]
COMP519 Web Programming Lecture 29 Slide L29 32