Ch1. The Internet
Ch2. The Internet protocol stack
Ch3. Web Servers
Ch4. HTML
Ch5. Apache and PHP
Ch6. Databases
Ch7. Databases and PHP
Ch8. Business Logic and JavaScript
Ch9. Security
Ch8. Business Logic and JavaScript
I. PHP business logic
1. Get available cars:
Need a logic to avoid this overlapping:
(1) The rentals start before the requested end date
(2) The rentals end after the requested start date
➔ Logic: rental.startDate < request.endDate && rental.endDate > request.startDate
2. Data flow
(1) Browser: GET searchresults.php?startDate=2019-05-20&endDate=2019-05-22
HTTP/1.1
(2) Web server (PHP interpreter): send SELECT query to DB
(3) DB: Return car table + rental table.
(4) The searchresults.php proceed data and return the list of available cars to the browser
(client).
3. Get available cars (function)
(1) Get all rentals from DB
(2) Find overlapping rentals with our request
(3) Store overlapping rentals in a list of as rented cars
(4) Get all cars (ID) from DB
(5) Available cars = All cars – rented cars
II. Improving our architecture
Improve by dividing web server into 2 main blocks:
➢ Front end: only focuses on creating HTML.
➢ REST API Server:
- focus on dealing with data.
➔ Advantage: Separation of concern.
The browser can directly communicate with REST API server:
e.g. while you are typing, the browser may send it to the server, asking for recommendations.
➔ To do this, we need data exchange formats (XML, JSON).
1. Data exchange format
Ch2. The Internet protocol stack
Ch3. Web Servers
Ch4. HTML
Ch5. Apache and PHP
Ch6. Databases
Ch7. Databases and PHP
Ch8. Business Logic and JavaScript
Ch9. Security
Ch8. Business Logic and JavaScript
I. PHP business logic
1. Get available cars:
Need a logic to avoid this overlapping:
(1) The rentals start before the requested end date
(2) The rentals end after the requested start date
➔ Logic: rental.startDate < request.endDate && rental.endDate > request.startDate
2. Data flow
(1) Browser: GET searchresults.php?startDate=2019-05-20&endDate=2019-05-22
HTTP/1.1
(2) Web server (PHP interpreter): send SELECT query to DB
(3) DB: Return car table + rental table.
(4) The searchresults.php proceed data and return the list of available cars to the browser
(client).
3. Get available cars (function)
(1) Get all rentals from DB
(2) Find overlapping rentals with our request
(3) Store overlapping rentals in a list of as rented cars
(4) Get all cars (ID) from DB
(5) Available cars = All cars – rented cars
II. Improving our architecture
Improve by dividing web server into 2 main blocks:
➢ Front end: only focuses on creating HTML.
➢ REST API Server:
- focus on dealing with data.
➔ Advantage: Separation of concern.
The browser can directly communicate with REST API server:
e.g. while you are typing, the browser may send it to the server, asking for recommendations.
➔ To do this, we need data exchange formats (XML, JSON).
1. Data exchange format