SlideShare a Scribd company logo
1 of 36
Download to read offline
Creating an API with
Expressive
Who?
Elton Minetto
Developer since 1997
Teacher since 2004
Co-founder at Coderockr since 2010
Zend Framework Evangelist
Author of http://bit.ly/zf2napratica and http://bit.ly/
doctrinenapratica
@eminetto
API
What?
"[] a set of routines, protocols, and tools for
building software applications. An API expresses a
software component in terms of its operations,
inputs, outputs, and underlying types []"
Wikipedia
Why?
Multiple interfaces
(web, mobile, CLI)
Integration with internal services
Sofware/Infrastructure as a Service
(Amazon, Parse, Pusher, Filepicker, etc)
Example
RestBeer
API about 🍻
Multiple response formats (JSON, HTML)
http://restbeer.com/beer
http://restbeer.com/style
http://restbeer.com/beer/Guinness
http://restbeer.com/beer/Heineken
http://restbeer.com/style/Pilsen
http://restbeer.com/style/Stout
Expressive
"Expressive allows you to write PSR-7
middleware applications for the web. It is a
simple micro-framework built on top of
Stratigility, providing:
Dynamic routing
Dependency injection via container-interop
Templating
Error Handling"
http://devzone.zend.com/6615/announcing-expressive/
Installing
composer.json
{
"require": {
"zendframework/zend-expressive": "^0.1.0",
"aura/router": "^2.3",
"zendframework/zend-servicemanager": "^2.6"
}
}
Installing
curl -s http://getcomposer.org/installer | php
php composer.phar install
Show 🍻
<?php
use AuraRouterRouterFactory;
use ZendExpressiveAppFactory;
use ZendExpressiveRouterAura as AuraBridge;
require 'vendor/autoload.php';
$auraRouter = (new RouterFactory())->newInstance();
$router = new AuraBridge($auraRouter);
$app = AppFactory::create(null, $router);
$beers = array(
'brands' => array('Heineken', 'Guinness', 'Skol', 'Colorado'),
'styles' => array('Pilsen' , 'Stout')
);
$app->get('/', function ($request, $response, $next) {
$response->getBody()->write('Hello, beers of world!');
return $response;
});
$app->get('/brand', function ($request, $response, $next) use ($beers) {
$response->getBody()->write(implode(',', $beers['brands']));
return $response;
});
$app->get('/style', function ($request, $response, $next) use ($beers) {
$response->getBody()->write(implode(',', $beers['styles']));
return $response;
});
$app->run();
Testing
php -S localhost:8080
Show a 🍺
$app->get('/beer{/id}', function ($request, $response,
$next) use ($beers) {
$id = $request->getAttribute('id');
if ($id == null) {
$response->getBody()->write(
implode(',', $beers['brands'])
);
return $response;
}
$key = array_search($id, $beers['brands']);
if ($key === false) {
$response->getBody()->write('Not found');
return $response;
}
$response->getBody()->write($beers['brands'][$key]);
return $response;
});
JSON!
https://gist.github.com/eminetto/5477c1da39f36d061fee
Authentication
index.php
https://gist.github.com/eminetto/197e48af07ad75db0fc2
srcRestBeerAuth.php
https://gist.github.com/eminetto/26a2e40f63fb4f1c7546
Add a 🍺
https://gist.github.com/eminetto/f9e44c18314b7aaaf66b
HTML and JSON!
{
"require": {
"zendframework/zend-expressive": "^0.1.0",
"aura/router": "^2.3",
"zendframework/zend-servicemanager": "^2.6",
"twig/twig": "*"
}
}
<!-- views/content.twig -->
{% for c in content %}
{{c}}<br>
{% endfor %}
index.php
https://gist.github.com/eminetto/4509a6cc5defe2b49d5a
srcRestBeerFormat.php
https://gist.github.com/eminetto/88114420d9c2b57708f6
Links
http://zend-expressive.readthedocs.org/en/stable/
https://github.com/zendframework/zend-
stratigility
Contact
http://eltonminetto.net
@eminetto
eminetto@coderockr.com
http://asemanaphp.com.br
http://coderockr.com

More Related Content

Viewers also liked

Viewers also liked (19)

Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
 
Zend\Expressive - höher, schneller, weiter
Zend\Expressive - höher, schneller, weiterZend\Expressive - höher, schneller, weiter
Zend\Expressive - höher, schneller, weiter
 
Apigility – Lightning Fast API Development - OSSCamp 2014
Apigility – Lightning Fast API Development - OSSCamp 2014 Apigility – Lightning Fast API Development - OSSCamp 2014
Apigility – Lightning Fast API Development - OSSCamp 2014
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
 
Introduction to git and github
Introduction to git and githubIntroduction to git and github
Introduction to git and github
 
Wordcampnigeria
WordcampnigeriaWordcampnigeria
Wordcampnigeria
 
Love Creating!
Love Creating!Love Creating!
Love Creating!
 
Tunesoflovepreview
TunesoflovepreviewTunesoflovepreview
Tunesoflovepreview
 
AIESEC Nigeria Corporate Portfolio
AIESEC Nigeria Corporate PortfolioAIESEC Nigeria Corporate Portfolio
AIESEC Nigeria Corporate Portfolio
 
Zend Expressive in 15 Minutes
Zend Expressive in 15 MinutesZend Expressive in 15 Minutes
Zend Expressive in 15 Minutes
 
IPC 2015 Zend Framework 3 Reloaded
IPC 2015 Zend Framework 3 ReloadedIPC 2015 Zend Framework 3 Reloaded
IPC 2015 Zend Framework 3 Reloaded
 
Rest Beer v2
Rest Beer v2Rest Beer v2
Rest Beer v2
 
Criando API Rest no Zend Framework 2
Criando API Rest no Zend Framework 2Criando API Rest no Zend Framework 2
Criando API Rest no Zend Framework 2
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
REST Level 5 - A Trek To The Summit
REST Level 5 - A Trek To The SummitREST Level 5 - A Trek To The Summit
REST Level 5 - A Trek To The Summit
 
Theory Of Design
Theory Of DesignTheory Of Design
Theory Of Design
 
Rest api design by george reese
Rest api design by george reeseRest api design by george reese
Rest api design by george reese
 
Level 3 REST Makes Your API Browsable
Level 3 REST Makes Your API BrowsableLevel 3 REST Makes Your API Browsable
Level 3 REST Makes Your API Browsable
 
reveal.js 3.0.0
reveal.js 3.0.0reveal.js 3.0.0
reveal.js 3.0.0
 

Similar to Creating an API with Expressive

Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web API
Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web APISinergija2012 - Developing REST API for Windows Azure with ASP.NET Web API
Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web API
Radenko Zec
 
The API Economy is Here: Facebook, Twitter, Netflix and Your IT Enterprise
The API Economy is Here: Facebook, Twitter, Netflix and Your IT EnterpriseThe API Economy is Here: Facebook, Twitter, Netflix and Your IT Enterprise
The API Economy is Here: Facebook, Twitter, Netflix and Your IT Enterprise
Akana
 
The API Economy is Here: Facebook, Twitter, Netflix and Your IT Enterprise
The API Economy is Here: Facebook, Twitter, Netflix and Your IT EnterpriseThe API Economy is Here: Facebook, Twitter, Netflix and Your IT Enterprise
The API Economy is Here: Facebook, Twitter, Netflix and Your IT Enterprise
Akana
 
Restful Integration with WSO2 ESB
Restful Integration with WSO2 ESB Restful Integration with WSO2 ESB
Restful Integration with WSO2 ESB
WSO2
 

Similar to Creating an API with Expressive (20)

Weekly Tech Session
Weekly Tech SessionWeekly Tech Session
Weekly Tech Session
 
main report on restaurant
main report on restaurantmain report on restaurant
main report on restaurant
 
LAJUG Napster REST API
LAJUG Napster REST APILAJUG Napster REST API
LAJUG Napster REST API
 
REST based API
REST based APIREST based API
REST based API
 
Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web API
Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web APISinergija2012 - Developing REST API for Windows Azure with ASP.NET Web API
Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web API
 
xcfgdfbn
xcfgdfbnxcfgdfbn
xcfgdfbn
 
APIs y seguridad
APIs y seguridadAPIs y seguridad
APIs y seguridad
 
APIdays 2015 - The State of Web API Languages
APIdays 2015 - The State of Web API LanguagesAPIdays 2015 - The State of Web API Languages
APIdays 2015 - The State of Web API Languages
 
APIdays 2015 - The State of Web API Languages
APIdays 2015 - The State of Web API LanguagesAPIdays 2015 - The State of Web API Languages
APIdays 2015 - The State of Web API Languages
 
Why Javascript is the glue of APIs?
Why Javascript is the glue of APIs?Why Javascript is the glue of APIs?
Why Javascript is the glue of APIs?
 
The API Economy is Here: Facebook, Twitter, Netflix and Your IT Enterprise
The API Economy is Here: Facebook, Twitter, Netflix and Your IT EnterpriseThe API Economy is Here: Facebook, Twitter, Netflix and Your IT Enterprise
The API Economy is Here: Facebook, Twitter, Netflix and Your IT Enterprise
 
TECHNOLOGY FOR BACK-END WEB DEVELOPMENT: SERVER-SIDE SCRIPTING
TECHNOLOGY FOR BACK-END WEB DEVELOPMENT: SERVER-SIDE SCRIPTING TECHNOLOGY FOR BACK-END WEB DEVELOPMENT: SERVER-SIDE SCRIPTING
TECHNOLOGY FOR BACK-END WEB DEVELOPMENT: SERVER-SIDE SCRIPTING
 
Using eZ Platform in an API Era
Using eZ Platform in an API EraUsing eZ Platform in an API Era
Using eZ Platform in an API Era
 
Azure Global Bootcamp 2017 - Microsoft Cognitive Services
Azure Global Bootcamp 2017 - Microsoft Cognitive ServicesAzure Global Bootcamp 2017 - Microsoft Cognitive Services
Azure Global Bootcamp 2017 - Microsoft Cognitive Services
 
Best practices and advantages of REST APIs
Best practices and advantages of REST APIsBest practices and advantages of REST APIs
Best practices and advantages of REST APIs
 
Enyo Hackathon Presentation
Enyo Hackathon PresentationEnyo Hackathon Presentation
Enyo Hackathon Presentation
 
The API Economy is Here: Facebook, Twitter, Netflix and Your IT Enterprise
The API Economy is Here: Facebook, Twitter, Netflix and Your IT EnterpriseThe API Economy is Here: Facebook, Twitter, Netflix and Your IT Enterprise
The API Economy is Here: Facebook, Twitter, Netflix and Your IT Enterprise
 
Restful Integration with WSO2 ESB
Restful Integration with WSO2 ESB Restful Integration with WSO2 ESB
Restful Integration with WSO2 ESB
 
solution Challenge design and flutter day.pptx
solution Challenge design and flutter day.pptxsolution Challenge design and flutter day.pptx
solution Challenge design and flutter day.pptx
 
PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cin...
PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cin...PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cin...
PHP is the king, nodejs is the prince and Python is the fool - Alessandro Cin...
 

More from Elton Minetto

More from Elton Minetto (20)

Go e Microserviços - Nascidos um para o outro
Go e Microserviços - Nascidos um para o outroGo e Microserviços - Nascidos um para o outro
Go e Microserviços - Nascidos um para o outro
 
Object Calisthenics em Go
Object Calisthenics em GoObject Calisthenics em Go
Object Calisthenics em Go
 
Programar != desenvolver software (v2)
Programar != desenvolver software (v2)Programar != desenvolver software (v2)
Programar != desenvolver software (v2)
 
Gerenciando uma startup no Github Projects
Gerenciando uma startup no Github ProjectsGerenciando uma startup no Github Projects
Gerenciando uma startup no Github Projects
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Serverless em Go
Serverless em GoServerless em Go
Serverless em Go
 
JAMstack
JAMstackJAMstack
JAMstack
 
Clean architecture em Go - v2
Clean architecture em Go - v2Clean architecture em Go - v2
Clean architecture em Go - v2
 
Programar != desenvolver software
Programar != desenvolver softwareProgramar != desenvolver software
Programar != desenvolver software
 
Clean Architecture em PHP
Clean Architecture em PHPClean Architecture em PHP
Clean Architecture em PHP
 
Clean Architecture in Golang
Clean Architecture in GolangClean Architecture in Golang
Clean Architecture in Golang
 
A jornada do desenvolvedor
A jornada do desenvolvedorA jornada do desenvolvedor
A jornada do desenvolvedor
 
Product and Technology
Product and TechnologyProduct and Technology
Product and Technology
 
Code:Nation Tech Stack
Code:Nation Tech StackCode:Nation Tech Stack
Code:Nation Tech Stack
 
Modernizando projetos legados usando APIs
Modernizando projetos legados usando APIsModernizando projetos legados usando APIs
Modernizando projetos legados usando APIs
 
12 factor in the PHP world
12 factor in the PHP world12 factor in the PHP world
12 factor in the PHP world
 
Building APIs using Go
Building APIs using GoBuilding APIs using Go
Building APIs using Go
 
Start you
Start youStart you
Start you
 
O case da Compufácil e AWS
O case da Compufácil e AWSO case da Compufácil e AWS
O case da Compufácil e AWS
 
Introdução a Go
Introdução a GoIntrodução a Go
Introdução a Go
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Creating an API with Expressive