Don't worry be “API” / JaB 2014
Frankfurt©Flickr-JensMayer
How are you ?
→ Have an API or plan one ?
→ Developer / designer / integrator ?
→ How many APIs have you already use
today...
Pierre-André Vullioud
Watchful.li CTO
Joomla enthusiast
Owner of inetis.ch
#pavullioud
APIs in 2014
source : www.programmableweb.com/api-research
Amazon
→ All teams will expose their data and functionality
through API.
→ There will be no other form of interprocess
com...
Open your system
→ Internal use
→ Apps
→ Clients
→ Partners
Data
API
Functionality
app
partners
services
REST
Everything is a resource
verbs : GET, PUT, POST, DELETE, PATCH
GET /sessions
Relations
GET /speakers/12/sessions
Filtering, sorting,
GET /sessions?date=20140601
GET /sessions?sort=+date,+name
Limit fields, callback
GET /sessions?fields=date,name,id
GET /sessions?callback=myFunction
API interfaces for Joomla
J!1.5 : XML-RPC
J!2.5 : com_api
J!3.2 : com_ajax and com_api
External solution : Slim Framework
com_api
for J! 2.5 & 3.x
a component by Techjoomla
extended by plugins
Example of call : index.php?
option=com_api&app=jab...
com_api
Pro
inside Joomla
compatible 2.5/3.x
Con
code based on J!1.5
URL not clean or fight
with router.php
com_ajax
Since J! 3.2 in the core
Extended by plugins & modules
First use for intern ajax call
Example of call : index.php...
com_ajax
Pro
core of Joomla
compatible J!1.5/2.5/3.x
Con
URLs not clean
Slim Framework
PHP micro framework
REST URLs based
Light
Example of call :
/api/v1/sessions/12
slimframework.com
Slim Framework
Pro
Clean URLs
RESTFull
Cons
Not inside J!
Need to learn
Files
api/ Slim
v1/
{..}
.htaccess
index.php
End point = https://mysite.
com/api/v1/session
Weeding J!Slim
require_once ( JPATH_BASE . '/includes/defines.php' );
require_once ( JPATH_BASE . '/includes/framework.php...
Add Middleware
$app = new SlimSlim
$app->_db = JFactory::getDbo();
$app->view(new JsonApiView());
$app->add(new JsonApiMid...
Define route and execute
$app->get('/', function() use ($app) {
$app->render(200, array(
'msg' => 'You reach the JAB API V...
Demo
Documentation
API is only as good as its
documentation
Swagger
describing, producing, consuming, and
visualizing RESTful web services
Specification: https://github.com/wordnik/s...
PHP comments
* @SWGApi(
* path="/logs/metadata",
* @SWGOperation(
* method="GET",
* summary="Get the list of fields",
* no...
Parse the code
Code Parser
JSON
output
Use it
Generate online documentation
http://petstore.swagger.wordnik.com/
Generate clients in different languages
https://...
Other tools
Consoles :
App for chrome
Online console
API proxy :
http://apigee.com
http://www.3scale.net
http://www.masher...
Questions ?
Ressources
Github : https://github.
com/pvullioud/joomla-slimframework
Upcoming SlideShare
Loading in …5
×

Don't worry be API with Slim framework and Joomla

3,441 views

Published on



Jab14 exemple of integration of Joomla and slim Framework

http://jandbeyond.org/program/sessions/dont-worry-be-api-best-practices-and-implementatio.html

In the context of a website or web application, an application-programming interface or API allows software developers to interact with and build upon the data and/or services delivered by your website. Thus, APIs provide limitless flexibility, reach and innovative potential for any website, service or application.

During the last few months, Pierre-André has performed extensive research and development to discover effective ways of adding an API to a Joomla website. In this interactive session, he will share his findings.

Attendees can expect to learn, why you need an API for your web site, the pros and cons of various API solutions, and why a RESTful API is a good fit for Joomla. Best practices for implementing a well-documented, pragmatic, and RESTful API will be discussed, along with useful tools and sample code for using the com_api component as well as Slim Framework.

Published in: Internet, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,441
On SlideShare
0
From Embeds
0
Number of Embeds
261
Actions
Shares
0
Downloads
29
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Don't worry be API with Slim framework and Joomla

  1. 1. Don't worry be “API” / JaB 2014 Frankfurt©Flickr-JensMayer
  2. 2. How are you ? → Have an API or plan one ? → Developer / designer / integrator ? → How many APIs have you already use today ?
  3. 3. Pierre-André Vullioud Watchful.li CTO Joomla enthusiast Owner of inetis.ch #pavullioud
  4. 4. APIs in 2014 source : www.programmableweb.com/api-research
  5. 5. Amazon → All teams will expose their data and functionality through API. → There will be no other form of interprocess communication [..] → Anyone who doesn't do this will be fired. Amazon policy set by Jeff Bezos in 2003
  6. 6. Open your system → Internal use → Apps → Clients → Partners Data API Functionality app partners services
  7. 7. REST Everything is a resource verbs : GET, PUT, POST, DELETE, PATCH GET /sessions
  8. 8. Relations GET /speakers/12/sessions
  9. 9. Filtering, sorting, GET /sessions?date=20140601 GET /sessions?sort=+date,+name
  10. 10. Limit fields, callback GET /sessions?fields=date,name,id GET /sessions?callback=myFunction
  11. 11. API interfaces for Joomla J!1.5 : XML-RPC J!2.5 : com_api J!3.2 : com_ajax and com_api External solution : Slim Framework
  12. 12. com_api for J! 2.5 & 3.x a component by Techjoomla extended by plugins Example of call : index.php? option=com_api&app=jab&format=raw&resource=sessions&id=14&api _key=123456qwert12 http://techjoomla.com/rest-api-for-joomla
  13. 13. com_api Pro inside Joomla compatible 2.5/3.x Con code based on J!1.5 URL not clean or fight with router.php
  14. 14. com_ajax Since J! 3.2 in the core Extended by plugins & modules First use for intern ajax call Example of call : index.php? option=com_ajax&plugin=session&format=json http://docs.joomla.org/Using_Joomla_Ajax_Interface
  15. 15. com_ajax Pro core of Joomla compatible J!1.5/2.5/3.x Con URLs not clean
  16. 16. Slim Framework PHP micro framework REST URLs based Light Example of call : /api/v1/sessions/12 slimframework.com
  17. 17. Slim Framework Pro Clean URLs RESTFull Cons Not inside J! Need to learn
  18. 18. Files api/ Slim v1/ {..} .htaccess index.php End point = https://mysite. com/api/v1/session
  19. 19. Weeding J!Slim require_once ( JPATH_BASE . '/includes/defines.php' ); require_once ( JPATH_BASE . '/includes/framework.php' ); $application = & JFactory::getApplication('site'); $application->initialise(); require '../Slim/Slim.php';
  20. 20. Add Middleware $app = new SlimSlim $app->_db = JFactory::getDbo(); $app->view(new JsonApiView()); $app->add(new JsonApiMiddleware());
  21. 21. Define route and execute $app->get('/', function() use ($app) { $app->render(200, array( 'msg' => 'You reach the JAB API V1' )); }); $app->map('/sessions/', function() use ($app) { ...})->via('GET'); $app->map('/sessions/:id', function($id) use ($app) { ...})->via ('GET'); $app->run();
  22. 22. Demo
  23. 23. Documentation API is only as good as its documentation
  24. 24. Swagger describing, producing, consuming, and visualizing RESTful web services Specification: https://github.com/wordnik/swagger-spec Swagger™ Demo: http://petstore.swagger.wordnik.com/
  25. 25. PHP comments * @SWGApi( * path="/logs/metadata", * @SWGOperation( * method="GET", * summary="Get the list of fields", * notes="Returns a list of fields", * type="Logs", * nickname="getFieldsLogs" (…)
  26. 26. Parse the code Code Parser JSON output
  27. 27. Use it Generate online documentation http://petstore.swagger.wordnik.com/ Generate clients in different languages https://github.com/wordnik/swagger-codegen Share you api : http://apicommons.org/apis.html
  28. 28. Other tools Consoles : App for chrome Online console API proxy : http://apigee.com http://www.3scale.net http://www.mashery.com/
  29. 29. Questions ?
  30. 30. Ressources Github : https://github. com/pvullioud/joomla-slimframework

×