+ All Categories
Transcript
Page 1: Don't worry be API with Slim framework and Joomla

Don't worry be “API” / JaB 2014

Alway’s be watching!

Fran

kfur

t ©Fl

ickr

- Je

ns M

ayer

Page 2: Don't worry be API with Slim framework and Joomla

How are you ?

→ Have an API or plan one ?→ Developer / designer / integrator ?→ How many APIs have you already use

today ?

Page 3: Don't worry be API with Slim framework and Joomla

Pierre-André Vullioud

Watchful.li CTO

Joomla enthusiast

Owner of inetis.ch

#pavullioud

Page 4: Don't worry be API with Slim framework and Joomla

APIs in 2014

source : www.programmableweb.com/api-research

Page 5: Don't worry be API with Slim framework and Joomla

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

Page 6: Don't worry be API with Slim framework and Joomla

Open your system

→ Internal use→ Apps→ Clients→ Partners

Data

API

Functionality

app

partnersservices

Page 7: Don't worry be API with Slim framework and Joomla

REST

Everything is a resource

verbs : GET, PUT, POST, DELETE, PATCH

GET /sessions

Page 8: Don't worry be API with Slim framework and Joomla

Relations

GET /speakers/12/sessions

Page 9: Don't worry be API with Slim framework and Joomla

Filtering, sorting,

GET /sessions?date=20140601

GET /sessions?sort=+date,+name

Page 10: Don't worry be API with Slim framework and Joomla

Limit fields, callback

GET /sessions?fields=date,name,id

GET /sessions?callback=myFunction

Page 11: Don't worry be API with Slim framework and Joomla

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

Page 12: Don't worry be API with Slim framework and Joomla

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

Page 13: Don't worry be API with Slim framework and 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

Page 14: Don't worry be API with Slim framework and Joomla

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

Page 15: Don't worry be API with Slim framework and Joomla

com_ajax

Pro

core of Joomla compatible J!1.5/2.5/3.x

Con

URLs not clean

Page 16: Don't worry be API with Slim framework and Joomla

Slim Framework

PHP micro framework

REST URLs based

LightExample of call :

/api/v1/sessions/12slimframework.com

Page 17: Don't worry be API with Slim framework and Joomla

Slim Framework

Pro

Clean URLs

RESTFull

Cons

Not inside J!

Need to learn

Page 18: Don't worry be API with Slim framework and Joomla

Files

api/ Slim

v1/

{..}

.htaccess

index.php

End point = https://mysite.com/api/v1/session

Page 19: Don't worry be API with Slim framework and Joomla

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';

Page 20: Don't worry be API with Slim framework and Joomla

Add Middleware

$app = new \Slim\Slim

$app->_db = JFactory::getDbo();

$app->view(new \JsonApiView());

$app->add(new \JsonApiMiddleware());

Page 21: Don't worry be API with Slim framework and Joomla

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();

Page 22: Don't worry be API with Slim framework and Joomla

Demo

Page 23: Don't worry be API with Slim framework and Joomla

Documentation

API is only as good as its documentation

Page 24: Don't worry be API with Slim framework and Joomla

Swagger

describing, producing, consuming, and visualizing RESTful web services

Specification: https://github.com/wordnik/swagger-spec

Swagger™ Demo: http://petstore.swagger.wordnik.com/

Page 25: Don't worry be API with Slim framework and Joomla

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" (…)

Page 26: Don't worry be API with Slim framework and Joomla

Parse the code

Code Parser JSON output

Page 27: Don't worry be API with Slim framework and Joomla

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

Page 28: Don't worry be API with Slim framework and Joomla

Other tools

Consoles :

App for chrome

Online console

API proxy :http://apigee.com

http://www.3scale.net

http://www.mashery.com/

Page 29: Don't worry be API with Slim framework and Joomla

Questions ?


Top Related