Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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 exposi...
REST Vs SOAP Cont…
REST permits many different data formats like (JSON, XML, CSV,RSS …)
SOAP only permits XML data formats...
REST Vs SOAP Cont…
REST is limited by HTTP itself which can’t provide two-phase commit across distributed
transactional re...
OVERVIEW
Slim is a dispatcher that receives an HTTP request, invokes an appropriate
callback routine, and returns an HTTP ...
Installation
System Requirements
o Web server with URL rewriting
o PHP 5.5 or newer
How to Install Slim
Install Slim with ...
Application
The Application, (or SlimApp) is the entry point to your Slim application and
is used to register the route th...
Application Configuration
The Application accepts just one argument. This can be either
a Container instance or an array t...
Request & Response
Slim app’s routes and middleware are given a PSR 7 request object that represents the
current HTTP requ...
Request & Response
The Application, (or SlimApp) is the entry point to your Slim application and is used to register the r...
The Request Headers
Every HTTP request has headers.
These are metadata that describe the HTTP request but are not visible ...
The Request Headers ….
Get All Headers: You can fetch all HTTP request headers as an associative array.
The Application, (...
The Request Headers ….
Get One Header: You can get a single header’s value(s) with the PSR 7 Request object’s
getHeader($n...
The Request Body
Following methods have request body
POST, PUT, PATCH
Slim can parse JSON, XML, and URL-encoded data out o...
The Request Body
You can get the HTTP request body StreamInterface instance with the PSR 7 Request
object’s getBody() meth...
Response Status
Every HTTP response has a numeric status code. The status code identifies the type of
HTTP response to be ...
Response Headers
Every HTTP response has headers. These are metadata that describe the HTTP response
but are not visible i...
Response Status
Set Header: You can set a header value with the PSR 7 Response object’s withHeader($name,
$value) method.
...
Returning JSON
Slim’s Response object has a custom method withJson($data, $status, $encodingOptions) to
help simplify the ...
Upcoming SlideShare
Loading in …5
×

Slim Framework

374 views

Published on

Slim is a PHP micro framework that helps you quickly write simple yet powerful REST API

Published in: Software
  • Be the first to comment

  • Be the first to like this

Slim Framework

  1. 1. Slim SLIM IS A PHP MICRO FRAMEWORK THAT HELPS YOU QUICKLY WRITE SIMPLE YET POWERFUL REST API PRAMOD KUMAR RAGHAV
  2. 2. REST Vs SOAP REST (Representational State Transfer)
  3. 3. REST Vs SOAP REST (Representational State Transfer) SOAP (Simple Object Access Protocol)
  4. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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.

×