SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Slim
SLIM IS A PHP MICRO FRAMEWORK THAT HELPS YOU QUICKLY WRITE SIMPLE YET POWERFUL REST API
PRAMOD KUMAR RAGHAV
REST Vs SOAP
REST (Representational State Transfer)
REST Vs SOAP
REST (Representational State Transfer)
SOAP (Simple Object Access Protocol)
REST Vs SOAP
REST (Representational State Transfer)
SOAP (Simple Object Access Protocol)
RESTs is good when you are exposing a public API over the internet to handle CRUD
operations on data. REST is focused on accessing named resources through a single consistent
interface.
SOAP brings it’s own protocol and focuses on exposing pieces of application logic (not data)
as services.
REST Vs SOAP Cont…
REST permits many different data formats like (JSON, XML, CSV,RSS …)
SOAP only permits XML data formats.
REST allows better support for browser clients due to it’s support for JSON.
REST reads can be cached, SOAP based reads cannot be cached.
SOAP support ACID Transactions over a service while REST isn’t ACID compliant.
REST Vs SOAP Cont…
REST is limited by HTTP itself which can’t provide two-phase commit across distributed
transactional resources, but SOAP can.
OVERVIEW
Slim is a dispatcher that receives an HTTP request, invokes an appropriate
callback routine, and returns an HTTP response. That’s it.
Installation
System Requirements
o Web server with URL rewriting
o PHP 5.5 or newer
How to Install Slim
Install Slim with Composer and execute the below command under your project
root directory.
composer require slim/slim "^3.0"
This command downloads the Slim Framework and its third-party dependencies
into your project’s vendor/ directory.
Application
The Application, (or SlimApp) is the entry point to your Slim application and
is used to register the route that link to your callbacks or controllers.
The Application, (or SlimApp) is the entry point to your Slim application and is used to register the route that link to your callbacks or controllers.
Application Configuration
The Application accepts just one argument. This can be either
a Container instance or an array to configure the default container that is
created automatically.
The Application, (or SlimApp) is the entry point to your Slim application and is used to register the route that link to your callbacks or controllers.
Request & Response
Slim app’s routes and middleware are given a PSR 7 request object that represents the
current HTTP request received by your web server.
The Application, (or SlimApp) is the entry point to your Slim application and is used to register the route that link to your callbacks or controllers.
 The PSR 7 request object is injected into your Slim application routes as the first argument
to the route callback.
 The PSR 7 response object is injected into your Slim application routes as the second
argument to the route callback.
Request & Response
The Application, (or SlimApp) is the entry point to your Slim application and is used to register the route that link to your callbacks or controllers.
The Request Headers
Every HTTP request has headers.
These are metadata that describe the HTTP request but are not visible in the request’s
body.
The Application, (or SlimApp) is the entry point to your Slim application and is used to register the route that link to your callbacks or controllers.
The Request Headers ….
Get All Headers: You can fetch all HTTP request headers as an associative array.
The Application, (or SlimApp) is the entry point to your Slim application and is used to register the route that link to your callbacks or controllers.
The Request Headers ….
Get One Header: You can get a single header’s value(s) with the PSR 7 Request object’s
getHeader($name) method. This returns an array of values for the given header name.
Remember, a single HTTP header may have more than one value!
The Request Body
Following methods have request body
POST, PUT, PATCH
Slim can parse JSON, XML, and URL-encoded data out of the box.
 JSON requests are converted into associative arrays with json_decode($input, true).
 XML requests are converted into a SimpleXMLElement with
simplexml_load_string($input).
 URL-encoded requests are converted into a PHP array with parse_str($input).
The Request Body
You can get the HTTP request body StreamInterface instance with the PSR 7 Request
object’s getBody() method. The getBody() method is preferable if the incoming HTTP
request size is unknown or too large for available memory.
 JSON requests are converted into associative arrays with json_decode($input, true).
 XML requests are converted into a SimpleXMLElement with
simplexml_load_string($input).
 URL-encoded requests are converted into a PHP array with parse_str($input).
Response Status
Every HTTP response has a numeric status code. The status code identifies the type of
HTTP response to be returned to the client.
You can copy a PSR 7 Response object and assign a new status code like this:
Response Headers
Every HTTP response has headers. These are metadata that describe the HTTP response
but are not visible in the response’s body.
Response Status
Set Header: You can set a header value with the PSR 7 Response object’s withHeader($name,
$value) method.
Append Header: You can append a header value with the PSR 7 Response object’s
withAddedHeader($name, $value) method.
Remove Header: You can remove a header with the Response object’s withoutHeader($name) method.
Returning JSON
Slim’s Response object has a custom method withJson($data, $status, $encodingOptions) to
help simplify the process of returning JSON data.
JSON data can be returned with a default 200 HTTP status code. But we can also return JSON data with
a custom HTTP status code.

Weitere ähnliche Inhalte

Was ist angesagt?

REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101Samantha Geitz
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkBo-Yi Wu
 
Designing CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIsDesigning CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIsNeil Crookes
 
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Caldera Labs
 
Making the Most of Modern PHP in Drupal 7
Making the Most of Modern PHP in Drupal 7Making the Most of Modern PHP in Drupal 7
Making the Most of Modern PHP in Drupal 7Ryan Szrama
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India
 
Introduction to plugin development
Introduction to plugin developmentIntroduction to plugin development
Introduction to plugin developmentCaldera Labs
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajaxs_pradeep
 
CakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIsCakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIsanthony_putignano
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroChristopher Pecoraro
 
Spray - Build RESTfull services in scala
Spray - Build RESTfull services in scalaSpray - Build RESTfull services in scala
Spray - Build RESTfull services in scalaSandeep Purohit
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with LaravelAbuzer Firdousi
 
Extending the WordPress REST API - Josh Pollock
Extending the WordPress REST API - Josh PollockExtending the WordPress REST API - Josh Pollock
Extending the WordPress REST API - Josh PollockCaldera Labs
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVCIndicThreads
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravelConfiz
 

Was ist angesagt? (20)

REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 
Psr-7
Psr-7Psr-7
Psr-7
 
Designing CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIsDesigning CakePHP plugins for consuming APIs
Designing CakePHP plugins for consuming APIs
 
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
 
Making the Most of Modern PHP in Drupal 7
Making the Most of Modern PHP in Drupal 7Making the Most of Modern PHP in Drupal 7
Making the Most of Modern PHP in Drupal 7
 
CakePHP REST Plugin
CakePHP REST PluginCakePHP REST Plugin
CakePHP REST Plugin
 
Day01 api
Day01   apiDay01   api
Day01 api
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
 
Introduction to plugin development
Introduction to plugin developmentIntroduction to plugin development
Introduction to plugin development
 
Javascript laravel's friend
Javascript laravel's friendJavascript laravel's friend
Javascript laravel's friend
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
 
CakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIsCakeFest 2013 - A-Z REST APIs
CakeFest 2013 - A-Z REST APIs
 
RESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher PecoraroRESTful API development in Laravel 4 - Christopher Pecoraro
RESTful API development in Laravel 4 - Christopher Pecoraro
 
Backbone js
Backbone jsBackbone js
Backbone js
 
Spray - Build RESTfull services in scala
Spray - Build RESTfull services in scalaSpray - Build RESTfull services in scala
Spray - Build RESTfull services in scala
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
Extending the WordPress REST API - Josh Pollock
Extending the WordPress REST API - Josh PollockExtending the WordPress REST API - Josh Pollock
Extending the WordPress REST API - Josh Pollock
 
Building RESTful applications using Spring MVC
Building RESTful applications using Spring MVCBuilding RESTful applications using Spring MVC
Building RESTful applications using Spring MVC
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 

Ähnlich wie Slim Framework

KaTe RESTful adapter for SAP Process Integration: Introduction
KaTe RESTful adapter for SAP Process Integration: IntroductionKaTe RESTful adapter for SAP Process Integration: Introduction
KaTe RESTful adapter for SAP Process Integration: IntroductionKate_RESTful
 
The introduction of RESTful
The introduction of RESTful The introduction of RESTful
The introduction of RESTful Jon Chen
 
Xamarin Workshop Noob to Master – Week 5
Xamarin Workshop Noob to Master – Week 5Xamarin Workshop Noob to Master – Week 5
Xamarin Workshop Noob to Master – Week 5Charlin Agramonte
 
Lunacloud's Compute RESTful API - Programmer's Guide
Lunacloud's Compute RESTful API - Programmer's GuideLunacloud's Compute RESTful API - Programmer's Guide
Lunacloud's Compute RESTful API - Programmer's GuideLunacloud
 
6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring FrameworkArcadian Learning
 
Rest and Sling Resolution
Rest and Sling ResolutionRest and Sling Resolution
Rest and Sling ResolutionDEEPAK KHETAWAT
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and ODataAnil Allewar
 
The RESTful Soa Datagrid with Oracle
The RESTful Soa Datagrid with OracleThe RESTful Soa Datagrid with Oracle
The RESTful Soa Datagrid with OracleEmiliano Pecis
 
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!Evan Mullins
 
Api wiki · git hub
Api wiki · git hubApi wiki · git hub
Api wiki · git hubFerry Irawan
 

Ähnlich wie Slim Framework (20)

Rest web service
Rest web serviceRest web service
Rest web service
 
Salesforce Integration
Salesforce IntegrationSalesforce Integration
Salesforce Integration
 
API Basics
API BasicsAPI Basics
API Basics
 
KaTe RESTful adapter for SAP Process Integration: Introduction
KaTe RESTful adapter for SAP Process Integration: IntroductionKaTe RESTful adapter for SAP Process Integration: Introduction
KaTe RESTful adapter for SAP Process Integration: Introduction
 
The introduction of RESTful
The introduction of RESTful The introduction of RESTful
The introduction of RESTful
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
Xamarin Workshop Noob to Master – Week 5
Xamarin Workshop Noob to Master – Week 5Xamarin Workshop Noob to Master – Week 5
Xamarin Workshop Noob to Master – Week 5
 
Lunacloud's Compute RESTful API - Programmer's Guide
Lunacloud's Compute RESTful API - Programmer's GuideLunacloud's Compute RESTful API - Programmer's Guide
Lunacloud's Compute RESTful API - Programmer's Guide
 
6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework6 Months Industrial Training in Spring Framework
6 Months Industrial Training in Spring Framework
 
Asp.net web api
Asp.net web apiAsp.net web api
Asp.net web api
 
Apitesting.pptx
Apitesting.pptxApitesting.pptx
Apitesting.pptx
 
Salesforce REST API
Salesforce  REST API Salesforce  REST API
Salesforce REST API
 
SFDC REST API
SFDC REST APISFDC REST API
SFDC REST API
 
Rest and Sling Resolution
Rest and Sling ResolutionRest and Sling Resolution
Rest and Sling Resolution
 
JAX-RS 2.0 and OData
JAX-RS 2.0 and ODataJAX-RS 2.0 and OData
JAX-RS 2.0 and OData
 
The RESTful Soa Datagrid with Oracle
The RESTful Soa Datagrid with OracleThe RESTful Soa Datagrid with Oracle
The RESTful Soa Datagrid with Oracle
 
Web Service
Web ServiceWeb Service
Web Service
 
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
 
Api wiki · git hub
Api wiki · git hubApi wiki · git hub
Api wiki · git hub
 
SCDJWS 6. REST JAX-P
SCDJWS 6. REST  JAX-PSCDJWS 6. REST  JAX-P
SCDJWS 6. REST JAX-P
 

Kürzlich hochgeladen

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 

Kürzlich hochgeladen (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

Slim Framework

  • 1. Slim SLIM IS A PHP MICRO FRAMEWORK THAT HELPS YOU QUICKLY WRITE SIMPLE YET POWERFUL REST API PRAMOD KUMAR RAGHAV
  • 2. REST Vs SOAP REST (Representational State Transfer)
  • 3. REST Vs SOAP REST (Representational State Transfer) SOAP (Simple Object Access Protocol)
  • 4. REST Vs SOAP REST (Representational State Transfer) SOAP (Simple Object Access Protocol) RESTs is good when you are exposing a public API over the internet to handle CRUD operations on data. REST is focused on accessing named resources through a single consistent interface. SOAP brings it’s own protocol and focuses on exposing pieces of application logic (not data) as services.
  • 5. REST Vs SOAP Cont… REST permits many different data formats like (JSON, XML, CSV,RSS …) SOAP only permits XML data formats. REST allows better support for browser clients due to it’s support for JSON. REST reads can be cached, SOAP based reads cannot be cached. SOAP support ACID Transactions over a service while REST isn’t ACID compliant.
  • 6. REST Vs SOAP Cont… REST is limited by HTTP itself which can’t provide two-phase commit across distributed transactional resources, but SOAP can.
  • 7. OVERVIEW Slim is a dispatcher that receives an HTTP request, invokes an appropriate callback routine, and returns an HTTP response. That’s it.
  • 8. Installation System Requirements o Web server with URL rewriting o PHP 5.5 or newer How to Install Slim Install Slim with Composer and execute the below command under your project root directory. composer require slim/slim "^3.0" This command downloads the Slim Framework and its third-party dependencies into your project’s vendor/ directory.
  • 9. Application The Application, (or SlimApp) is the entry point to your Slim application and is used to register the route that link to your callbacks or controllers. The Application, (or SlimApp) is the entry point to your Slim application and is used to register the route that link to your callbacks or controllers.
  • 10. Application Configuration The Application accepts just one argument. This can be either a Container instance or an array to configure the default container that is created automatically. The Application, (or SlimApp) is the entry point to your Slim application and is used to register the route that link to your callbacks or controllers.
  • 11. Request & Response Slim app’s routes and middleware are given a PSR 7 request object that represents the current HTTP request received by your web server. The Application, (or SlimApp) is the entry point to your Slim application and is used to register the route that link to your callbacks or controllers.  The PSR 7 request object is injected into your Slim application routes as the first argument to the route callback.  The PSR 7 response object is injected into your Slim application routes as the second argument to the route callback.
  • 12. Request & Response The Application, (or SlimApp) is the entry point to your Slim application and is used to register the route that link to your callbacks or controllers.
  • 13. The Request Headers Every HTTP request has headers. These are metadata that describe the HTTP request but are not visible in the request’s body. The Application, (or SlimApp) is the entry point to your Slim application and is used to register the route that link to your callbacks or controllers.
  • 14. The Request Headers …. Get All Headers: You can fetch all HTTP request headers as an associative array. The Application, (or SlimApp) is the entry point to your Slim application and is used to register the route that link to your callbacks or controllers.
  • 15. The Request Headers …. Get One Header: You can get a single header’s value(s) with the PSR 7 Request object’s getHeader($name) method. This returns an array of values for the given header name. Remember, a single HTTP header may have more than one value!
  • 16. The Request Body Following methods have request body POST, PUT, PATCH Slim can parse JSON, XML, and URL-encoded data out of the box.  JSON requests are converted into associative arrays with json_decode($input, true).  XML requests are converted into a SimpleXMLElement with simplexml_load_string($input).  URL-encoded requests are converted into a PHP array with parse_str($input).
  • 17. The Request Body You can get the HTTP request body StreamInterface instance with the PSR 7 Request object’s getBody() method. The getBody() method is preferable if the incoming HTTP request size is unknown or too large for available memory.  JSON requests are converted into associative arrays with json_decode($input, true).  XML requests are converted into a SimpleXMLElement with simplexml_load_string($input).  URL-encoded requests are converted into a PHP array with parse_str($input).
  • 18. Response Status Every HTTP response has a numeric status code. The status code identifies the type of HTTP response to be returned to the client. You can copy a PSR 7 Response object and assign a new status code like this:
  • 19. Response Headers Every HTTP response has headers. These are metadata that describe the HTTP response but are not visible in the response’s body.
  • 20. Response Status Set Header: You can set a header value with the PSR 7 Response object’s withHeader($name, $value) method. Append Header: You can append a header value with the PSR 7 Response object’s withAddedHeader($name, $value) method. Remove Header: You can remove a header with the Response object’s withoutHeader($name) method.
  • 21. Returning JSON Slim’s Response object has a custom method withJson($data, $status, $encodingOptions) to help simplify the process of returning JSON data. JSON data can be returned with a default 200 HTTP status code. But we can also return JSON data with a custom HTTP status code.