Click here to load reader
Date post: | 28-Jan-2015 |
Category: |
Internet |
Upload: | pierre-andre-vullioud |
View: | 119 times |
Download: | 1 times |
Click here to load reader
Don't worry be “API” / JaB 2014
Alway’s be watching!
Fran
kfur
t ©Fl
ickr
- Je
ns M
ayer
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 communication [..]
→ Anyone who doesn't do this will be fired.Amazon policy set by Jeff Bezos in 2003
Open your system
→ Internal use→ Apps→ Clients→ Partners
Data
API
Functionality
app
partnersservices
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 pluginsExample of call : index.php?option=com_api&app=jab&format=raw&resource=sessions&id=14&api_key=123456qwert12http://techjoomla.com/rest-api-for-joomla
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 callExample of call : index.php?option=com_ajax&plugin=session&format=jsonhttp://docs.joomla.org/Using_Joomla_Ajax_Interface
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
LightExample of call :
/api/v1/sessions/12slimframework.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' );
$application = & JFactory::getApplication('site');
$application->initialise();
require '../Slim/Slim.php';
Add Middleware
$app = new \Slim\Slim
$app->_db = JFactory::getDbo();
$app->view(new \JsonApiView());
$app->add(new \JsonApiMiddleware());
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();
Demo
Documentation
API is only as good as its documentation
Swagger
describing, producing, consuming, and visualizing RESTful web services
Specification: https://github.com/wordnik/swagger-spec
Swagger™ Demo: http://petstore.swagger.wordnik.com/
PHP comments
* @SWG\Api(
* path="/logs/metadata",
* @SWG\Operation(
* method="GET",
* summary="Get the list of fields",
* notes="Returns a list of fields",
* type="Logs",
* nickname="getFieldsLogs" (…)
Parse the code
Code Parser JSON output
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
Other tools
Consoles :
App for chrome
Online console
API proxy :http://apigee.com
http://www.3scale.net
http://www.mashery.com/
Questions ?
Ressources
Github : https://github.com/pvullioud/joomla-slimframework