Home >Internet >Don't worry be API with Slim framework and Joomla

Don't worry be API with Slim framework and Joomla

Date post:28-Jan-2015
View:110 times
Download:1 times
Share this document with a friend
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.
  • 1. Don't worry be API / JaB 2014 FrankfurtFlickr-JensMayer

2. How are you ? Have an API or plan one ? Developer / designer / integrator ? How many APIs have you already use today ? 3. Pierre-Andr Vullioud Watchful.li CTO Joomla enthusiast Owner of inetis.ch #pavullioud 4. APIs in 2014 source : www.programmableweb.com/api-research 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. Open your system Internal use Apps Clients Partners Data API Functionality app partners services 7. REST Everything is a resource verbs : GET, PUT, POST, DELETE, PATCH GET /sessions 8. Relations GET /speakers/12/sessions 9. Filtering, sorting, GET /sessions?date=20140601 GET /sessions?sort=+date,+name 10. Limit fields, callback GET /sessions?fields=date,name,id GET /sessions?callback=myFunction 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. 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. 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. 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. com_ajax Pro core of Joomla compatible J!1.5/2.5/3.x Con URLs not clean 16. Slim Framework PHP micro framework REST URLs based Light Example of call : /api/v1/sessions/12 slimframework.com 17. Slim Framework Pro Clean URLs RESTFull Cons Not inside J! Need to learn 18. Files api/ Slim v1/ {..} .htaccess index.php End point = https://mysite. com/api/v1/session 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. Add Middleware $app = new SlimSlim $app->_db = JFactory::getDbo(); $app->view(new JsonApiView()); $app->add(new JsonApiMiddleware()); 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. Demo 23. Documentation API is only as good as its documentation 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. 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. Parse the code Code Parser JSON output 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. Other tools Consoles : App for chrome Online console API proxy : http://apigee.com http://www.3scale.net http://www.mashery.com/ 29. Questions ? 30. Ressources Github : https://github. com/pvullioud/joomla-slimframework

Popular Tags:

Click here to load reader

Embed Size (px)