SlideShare a Scribd company logo
Advanced Web Development in PHP
Module VIII: Understanding REST
API
Rasan Samarasinghe
ESOFT Computer Studies (pvt) Ltd.
No 68/1, Main Street, Embilipitiya.
Contents
1. What is an API?
2. Comparing a website to an API
3. Classification of APIs
4. What is REST API?
5. What model does REST use?
6. REST HTTP Methods
7. HTTP Codes
8. The advantages of REST
9. What is CRUD?
10. CRUD Operations
11. CRUD Application Example
12. REST API Implementation
13. Folders and Files Structure
14. MySQL Database
15. Reading all Products
16. Reading one Product
17. Creating a Product
18. Updating a Product
19. Deleting a Product
20. Searching a Product
What is an API?
• API stands for Application Programming Interface.
• API’s basically allow your product or service to talk to
another product or service.
• Software-to-software interaction, not user interaction.
• They are used to give people access to your
data/resources from outside the firewall.
• This means opening up your product’s data and
functionality to other developers both internally and
externally.
Comparing a website to an API
Compare
GitHub Website
https://github.com/rasansmn
GitHub API
https://api.github.com/users/rasansmn
Classification of APIs
Web Service API
• SOAP
• XML-RPC and JSON-RPC
• REST
WebSocket APIs
Library-based APIs
• JavaScript
• TWAIN
Class-based APIs (Object
Orientation)
• Java API
• Android API
OS Functions and Routines
• Access to file system
• Access to user interface
Object Remoting APIs
• CORBA
• .NET Remoting
Hardware APIs
• Video acceleration
• Hard disk drives
• PCI buses
What is REST API?
• REST stands for Representational State Transfer.
• It is a lighter weight alternative to SOAP and WSDL
XML-based API protocols.
What model does REST use?
• REST uses a client-server model, where the server
is an HTTP server and the client sends HTTP verbs
(GET, POST, PUT, DELETE), along with a URL and
variable parameters that are URL-encoded.
• The URL describes the object to act upon and the
server replies with a result code and valid
JavaScript Object Notation (JSON).
What model does REST use?
REST HTTP Methods
Method Description
GET Request to read a webpage
HEAD Request to read a webpage’s header
PUT Request to store a webpage
POST Append to a names resource
DELETE Remove the webpage
TRACE Echo the incoming request
CONNECT Reserved for future use
OPTIONS Query certain options
HTTP Codes
• 200 - “OK”.
• 201 - “Created” (Used with POST).
• 400 - “Bad Request” (Perhaps missing required parameters).
• 401 - “Unauthorized” (Missing authentication parameters).
• 403 - “Forbidden” (You were authenticated but lacking required
privileges).
• 404 - “Not Found”.
The advantages of REST
• Separation between the client and the server.
• Visibility, reliability and scalability.
• The REST API is always independent of the type of
platform or languages.
• Lighter weight alternative to SOAP and WSDL
XML-based API protocols.
What is CRUD?
The CRUD acronym is often used to describe
database operations. CRUD stands for CREATE,
READ, UPDATE, and DELETE.
CRUD Operations
• POST: A client wants to insert or create an object.
• GET: A client wants to read an object.
• PUT: A client wants to update an object.
• DELETE: A client wants to delete an object.
CRUD Application Example
Simple REST API Implementation in PHP
REST API objects and their operations
• Products
– Read (all records)
– Read one
– Create
– Update
– Delete
– Search
• Categories
– Read (all records)
– Other operations has to be implemented as an exercise
Web root Folders and Files Structure
MySQL Database
Import MySQL database using api_db.sql dump file
Reading all Products
Using PostMan as the client to read all products
Reading one Product
Using PostMan as the client to read one product
Creating a Product
Using PostMan as the client to create a product
Updating a Product
Using PostMan as the client to update a product
Deleting a Product
Using PostMan as the client to delete a product
Searching a Product
Using PostMan as the client to search a product
The End
http://twitter.com/rasansmn

More Related Content

What's hot (20)

PPTX
Typescript ppt
akhilsreyas
 
PDF
SOAP-based Web Services
Katrien Verbert
 
PDF
React lecture
Christoffer Noring
 
PPTX
Advance Java Topics (J2EE)
slire
 
PPTX
OOP Introduction with java programming language
Md.Al-imran Roton
 
PPTX
Intro to React
Justin Reock
 
PPTX
JavaScript Promises
L&T Technology Services Limited
 
PPTX
Restful web services ppt
OECLIB Odisha Electronics Control Library
 
PPTX
React hooks
Ramy ElBasyouni
 
PPTX
Introduction to REST - API
Chetan Gadodia
 
PPTX
Object Oriented Programming In JavaScript
Forziatech
 
PDF
Use Node.js to create a REST API
Fabien Vauchelles
 
PPT
Advanced Javascript
Adieu
 
PDF
Angular Observables & RxJS Introduction
Rahat Khanna a.k.a mAppMechanic
 
PDF
ES6 presentation
ritika1
 
PDF
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
PDF
Introduction into ES6 JavaScript.
boyney123
 
PPTX
ASP.NET Core MVC + Web API with Overview
Shahed Chowdhuri
 
PDF
Angular and The Case for RxJS
Sandi Barr
 
PPTX
An Introduction To REST API
Aniruddh Bhilvare
 
Typescript ppt
akhilsreyas
 
SOAP-based Web Services
Katrien Verbert
 
React lecture
Christoffer Noring
 
Advance Java Topics (J2EE)
slire
 
OOP Introduction with java programming language
Md.Al-imran Roton
 
Intro to React
Justin Reock
 
JavaScript Promises
L&T Technology Services Limited
 
React hooks
Ramy ElBasyouni
 
Introduction to REST - API
Chetan Gadodia
 
Object Oriented Programming In JavaScript
Forziatech
 
Use Node.js to create a REST API
Fabien Vauchelles
 
Advanced Javascript
Adieu
 
Angular Observables & RxJS Introduction
Rahat Khanna a.k.a mAppMechanic
 
ES6 presentation
ritika1
 
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
Introduction into ES6 JavaScript.
boyney123
 
ASP.NET Core MVC + Web API with Overview
Shahed Chowdhuri
 
Angular and The Case for RxJS
Sandi Barr
 
An Introduction To REST API
Aniruddh Bhilvare
 

Similar to Advanced Web Development in PHP - Understanding REST API (20)

PDF
REST API and CRUD
Prem Sanil
 
PPTX
Apitesting.pptx
NamanVerma88
 
PPTX
advanced computer network, about computer
jishukurmi81
 
PPTX
Introduction to APIs (Application Programming Interface)
Vibhawa Nirmal
 
PDF
Introduction to REST - REST Basics - JSON
Matrix823409
 
PDF
zendframework2 restful
tom_li
 
PPTX
What is an API?
Muhammad Zuhdi
 
PDF
Applicaton Development using RESTful APIs
Sourav Maji
 
PDF
API Basics
Ritul Chaudhary
 
PDF
Web APIs
Carlos Santos
 
PDF
Ebook undisturbed rest-v1 [res_tful apis]
johnkbutcher
 
PPTX
introduction about REST API
AmilaSilva13
 
PPTX
API Development Essentials: REST, SOAP, GraphQL Explained
ankitraj5ar
 
PPTX
REST API
Kanushka Gayan
 
PDF
What is API - Understanding API Simplified
Jubin Aghara
 
PDF
IRJET- Rest API for E-Commerce Site
IRJET Journal
 
PPTX
Distributed systems air traffic controller
nazimsattar
 
PPTX
rest-api-basics.pptx
AgungSutikno1
 
PDF
Coding 100-session-slides
Cisco DevNet
 
PPTX
REST API
Tofazzal Ahmed
 
REST API and CRUD
Prem Sanil
 
Apitesting.pptx
NamanVerma88
 
advanced computer network, about computer
jishukurmi81
 
Introduction to APIs (Application Programming Interface)
Vibhawa Nirmal
 
Introduction to REST - REST Basics - JSON
Matrix823409
 
zendframework2 restful
tom_li
 
What is an API?
Muhammad Zuhdi
 
Applicaton Development using RESTful APIs
Sourav Maji
 
API Basics
Ritul Chaudhary
 
Web APIs
Carlos Santos
 
Ebook undisturbed rest-v1 [res_tful apis]
johnkbutcher
 
introduction about REST API
AmilaSilva13
 
API Development Essentials: REST, SOAP, GraphQL Explained
ankitraj5ar
 
REST API
Kanushka Gayan
 
What is API - Understanding API Simplified
Jubin Aghara
 
IRJET- Rest API for E-Commerce Site
IRJET Journal
 
Distributed systems air traffic controller
nazimsattar
 
rest-api-basics.pptx
AgungSutikno1
 
Coding 100-session-slides
Cisco DevNet
 
REST API
Tofazzal Ahmed
 
Ad

More from Rasan Samarasinghe (20)

PPTX
Managing the under performance in projects.pptx
Rasan Samarasinghe
 
PPTX
Agile project management with scrum
Rasan Samarasinghe
 
PPTX
Introduction to Agile
Rasan Samarasinghe
 
PPSX
IT Introduction (en)
Rasan Samarasinghe
 
PPSX
Application of Unified Modelling Language
Rasan Samarasinghe
 
PPSX
Advanced Web Development in PHP - Understanding Project Development Methodolo...
Rasan Samarasinghe
 
PPSX
Advanced Web Development in PHP - Code Versioning and Branching with Git
Rasan Samarasinghe
 
PPSX
DIWE - Working with MySQL Databases
Rasan Samarasinghe
 
PPSX
DIWE - Using Extensions and Image Manipulation
Rasan Samarasinghe
 
PPSX
DIWE - File handling with PHP
Rasan Samarasinghe
 
PPSX
DIWE - Advanced PHP Concepts
Rasan Samarasinghe
 
PPSX
DIWE - Fundamentals of PHP
Rasan Samarasinghe
 
PPSX
DIWE - Programming with JavaScript
Rasan Samarasinghe
 
PPSX
DIWE - Coding HTML for Basic Web Designing
Rasan Samarasinghe
 
PPSX
DIWE - Multimedia Technologies
Rasan Samarasinghe
 
PPSX
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
PPSX
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
PPSX
Esoft Metro Campus - Certificate in java basics
Rasan Samarasinghe
 
PPSX
DISE - Software Testing and Quality Management
Rasan Samarasinghe
 
PPSX
DISE - Introduction to Project Management
Rasan Samarasinghe
 
Managing the under performance in projects.pptx
Rasan Samarasinghe
 
Agile project management with scrum
Rasan Samarasinghe
 
Introduction to Agile
Rasan Samarasinghe
 
IT Introduction (en)
Rasan Samarasinghe
 
Application of Unified Modelling Language
Rasan Samarasinghe
 
Advanced Web Development in PHP - Understanding Project Development Methodolo...
Rasan Samarasinghe
 
Advanced Web Development in PHP - Code Versioning and Branching with Git
Rasan Samarasinghe
 
DIWE - Working with MySQL Databases
Rasan Samarasinghe
 
DIWE - Using Extensions and Image Manipulation
Rasan Samarasinghe
 
DIWE - File handling with PHP
Rasan Samarasinghe
 
DIWE - Advanced PHP Concepts
Rasan Samarasinghe
 
DIWE - Fundamentals of PHP
Rasan Samarasinghe
 
DIWE - Programming with JavaScript
Rasan Samarasinghe
 
DIWE - Coding HTML for Basic Web Designing
Rasan Samarasinghe
 
DIWE - Multimedia Technologies
Rasan Samarasinghe
 
Esoft Metro Campus - Programming with C++
Rasan Samarasinghe
 
Esoft Metro Campus - Certificate in c / c++ programming
Rasan Samarasinghe
 
Esoft Metro Campus - Certificate in java basics
Rasan Samarasinghe
 
DISE - Software Testing and Quality Management
Rasan Samarasinghe
 
DISE - Introduction to Project Management
Rasan Samarasinghe
 
Ad

Recently uploaded (20)

PDF
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
PPTX
Securing Model Context Protocol with Keycloak: AuthN/AuthZ for MCP Servers
Hitachi, Ltd. OSS Solution Center.
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
PDF
Next Generation AI: Anticipatory Intelligence, Forecasting Inflection Points ...
dleka294658677
 
PDF
Sound the Alarm: Detection and Response
VICTOR MAESTRE RAMIREZ
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
Governing Geospatial Data at Scale: Optimizing ArcGIS Online with FME in Envi...
Safe Software
 
PDF
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
Deploy Faster, Run Smarter: Learn Containers with QNAP
QNAP Marketing
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
FME in Overdrive: Unleashing the Power of Parallel Processing
Safe Software
 
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
Securing Model Context Protocol with Keycloak: AuthN/AuthZ for MCP Servers
Hitachi, Ltd. OSS Solution Center.
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
Next Generation AI: Anticipatory Intelligence, Forecasting Inflection Points ...
dleka294658677
 
Sound the Alarm: Detection and Response
VICTOR MAESTRE RAMIREZ
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Governing Geospatial Data at Scale: Optimizing ArcGIS Online with FME in Envi...
Safe Software
 
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
Deploy Faster, Run Smarter: Learn Containers with QNAP
QNAP Marketing
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
FME in Overdrive: Unleashing the Power of Parallel Processing
Safe Software
 

Advanced Web Development in PHP - Understanding REST API

  • 1. Advanced Web Development in PHP Module VIII: Understanding REST API Rasan Samarasinghe ESOFT Computer Studies (pvt) Ltd. No 68/1, Main Street, Embilipitiya.
  • 2. Contents 1. What is an API? 2. Comparing a website to an API 3. Classification of APIs 4. What is REST API? 5. What model does REST use? 6. REST HTTP Methods 7. HTTP Codes 8. The advantages of REST 9. What is CRUD? 10. CRUD Operations 11. CRUD Application Example 12. REST API Implementation 13. Folders and Files Structure 14. MySQL Database 15. Reading all Products 16. Reading one Product 17. Creating a Product 18. Updating a Product 19. Deleting a Product 20. Searching a Product
  • 3. What is an API? • API stands for Application Programming Interface. • API’s basically allow your product or service to talk to another product or service. • Software-to-software interaction, not user interaction. • They are used to give people access to your data/resources from outside the firewall. • This means opening up your product’s data and functionality to other developers both internally and externally.
  • 6. Classification of APIs Web Service API • SOAP • XML-RPC and JSON-RPC • REST WebSocket APIs Library-based APIs • JavaScript • TWAIN Class-based APIs (Object Orientation) • Java API • Android API OS Functions and Routines • Access to file system • Access to user interface Object Remoting APIs • CORBA • .NET Remoting Hardware APIs • Video acceleration • Hard disk drives • PCI buses
  • 7. What is REST API? • REST stands for Representational State Transfer. • It is a lighter weight alternative to SOAP and WSDL XML-based API protocols.
  • 8. What model does REST use? • REST uses a client-server model, where the server is an HTTP server and the client sends HTTP verbs (GET, POST, PUT, DELETE), along with a URL and variable parameters that are URL-encoded. • The URL describes the object to act upon and the server replies with a result code and valid JavaScript Object Notation (JSON).
  • 9. What model does REST use?
  • 10. REST HTTP Methods Method Description GET Request to read a webpage HEAD Request to read a webpage’s header PUT Request to store a webpage POST Append to a names resource DELETE Remove the webpage TRACE Echo the incoming request CONNECT Reserved for future use OPTIONS Query certain options
  • 11. HTTP Codes • 200 - “OK”. • 201 - “Created” (Used with POST). • 400 - “Bad Request” (Perhaps missing required parameters). • 401 - “Unauthorized” (Missing authentication parameters). • 403 - “Forbidden” (You were authenticated but lacking required privileges). • 404 - “Not Found”.
  • 12. The advantages of REST • Separation between the client and the server. • Visibility, reliability and scalability. • The REST API is always independent of the type of platform or languages. • Lighter weight alternative to SOAP and WSDL XML-based API protocols.
  • 13. What is CRUD? The CRUD acronym is often used to describe database operations. CRUD stands for CREATE, READ, UPDATE, and DELETE.
  • 14. CRUD Operations • POST: A client wants to insert or create an object. • GET: A client wants to read an object. • PUT: A client wants to update an object. • DELETE: A client wants to delete an object.
  • 16. Simple REST API Implementation in PHP REST API objects and their operations • Products – Read (all records) – Read one – Create – Update – Delete – Search • Categories – Read (all records) – Other operations has to be implemented as an exercise
  • 17. Web root Folders and Files Structure
  • 18. MySQL Database Import MySQL database using api_db.sql dump file
  • 19. Reading all Products Using PostMan as the client to read all products
  • 20. Reading one Product Using PostMan as the client to read one product
  • 21. Creating a Product Using PostMan as the client to create a product
  • 22. Updating a Product Using PostMan as the client to update a product
  • 23. Deleting a Product Using PostMan as the client to delete a product
  • 24. Searching a Product Using PostMan as the client to search a product