Download - Restful Web Services Frap i
RESTFUL webservicesConstruindo Apis
Alex Piaz
http://joind.in/talk/view/4481
Agenda
Eu
Webservices
API's
Frapi
Demo
? quem sou eu ?
Mercantólogo por formação, desenvolvedor por paixão!
Ativista por consciência!
Há 15 anos nas interwebs...
Há 15 anos nas interwebs...
Há 15 anos nas interwebs...
http://web.archive.org/web/19961223175947/http://uol.com.br/
1996
Há 12 anos...
1998
Há 7 anos...
1998
Ah! Cem mil dólares! Mulheres, automóvel. Mulheres! Iate, mulheres, mansões, mulheres, ah!
Há 6 anos...
1998
Webservices
"a software system designed to support interoperable machine-to-machine interaction over a network"
http://www.w3.org/TR/ws-arch/#whatis
RPC
HTTP, SMTP ,FTP ,etc
getUser()
XML
ReST
HTTP
http://servidor/user/{user}
múltiplas saídas
É só fazer um "XML" que resolve....
Na vida real é um pouco mais complicado....
Autenticação
Documentação
Diferentes formatos de saída
Tratamento de erros
E o FRAPI entra em cena!
http://getfrapi.com
FRAMEWORK API
Interface administrativa
API Pública
Camadas de interação
• Zend Framework• Actions e Errors• Autenticação• Documentação• Ambiente de testes
• PHP Puro• Cache
INSTALAÇÃO
INSTALAÇÃO / Requisitos mínimos
o Webserver (apache, nginx, iis)
o PHP >= 5.2.4o gettexto XMLWritero APC *
* Pode ser instalado sem o APC ou com outro mecanismo de caching mas não é recomendado http://frapi.github.com/installing/caching.html
http://frapi.github.com/installing/index.html
INSTALAÇÃO / Obtendo o software
git clone git://github.com/frapi/frapi.git
ou
wget https://github.com/frapi/frapi/tarball/master
tar -xzvf frapi-frapi-VERSION.tar.gz
FRAPI_PATH = local/onde/voce/desempacotou/o/frapi
<VirtualHost *:80> ServerName admin.frapi DirectoryIndex index.php ServerAdmin [email protected]
# This should be omitted in the production environment SetEnv APPLICATION_ENV development
DocumentRoot FRAPI_PATH/src/frapi/admin/public <Directory FRAPI_PATH/src/frapi/admin/public> AllowOverride All Order deny,allow Allow from All </Directory></VirtualHost>
Interface Administrativa
<VirtualHost *:80> ServerName api.frapi ServerAdmin [email protected] DocumentRoot FRAPI_PATH/src/frapi/public
# This should be omitted in the production environment SetEnv APPLICATION_ENV development <Directory FRAPI_PATH/src/frapi/public> AllowOverride All Order deny,allow Allow from All </Directory></VirtualHost>
API Pública
INSTALAÇÃO / Configurando
2 virtual host
Permissões de acesso
chown -R username.web-user FRAPI_PATHchmod 775 FRAPI_PATH/src/frapi/custom/Actionchmod 775 FRAPI_PATH/src/frapi/custom/Config/chmod 664 FRAPI_PATH/src/frapi/custom/Config/*.xml
INSTALAÇÃO / Finalizando
UFO API
Principais casos da Ufologia Mundial em ReSTFul!
CRUD
UFO API
Modelo (Business Logic)
2 Mensagens de erro (sem resultados / não encontrado)
3 URLs === 3 actions
http://ufo-api.piaz.com.br/caso (POST)
http://ufo-api.piaz.com.br/caso/{id} (GET PUT DELETE)
http://ufo-api.piaz.com.br/casos (GET)
Filtros viram parâmetros na Querystring
http://ufo-api.piaz.com.br/casos?pais=Brasil
Principais casos da Ufologia Mundial em ReSTFul!
UFO API
Principais casos da Ufologia Mundial em ReSTFul!
Mensagens de erro
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
UFO API
Principais casos da Ufologia Mundial em ReSTFul!
Custom_Model_Caso()
getCasos()
getCaso($id)
insertCaso($data)
updateCaso($id,$data)
deleteCaso($id)
UFO API
Principais casos da Ufologia Mundial em ReSTFul!
Métodos disponibilizados pelo FRAPI
executeGet()
executePost()
executePut()
executeDelete()
executeHead()
http://frapi.github.com/developing/coding-actions.html
FRAPI_PATH/src/frapi/custom/Action
UFO API
Principais casos da Ufologia Mundial em ReSTFul!
ListaCasos - http://ufo-api.piaz.com.br/casos (GET)
UFO API
Principais casos da Ufologia Mundial em ReSTFul!
InsereCaso - http://ufo-api.piaz.com.br/caso (POST)
UFO API
Principais casos da Ufologia Mundial em ReSTFul!
Caso - http://ufo-api.piaz.com.br/caso/{id} (GET PUT DELETE)
Gerando documentação...
http://frapi-admin/docs/generate/format/texthttp://frapi-admin/docs/generate/format/htmlhttp://frapi-admin/docs/generate/format/mdownhttp://frapi-admin/docs/generate/format/pdf
Alex Piaz (@zaip)[email protected]://www.zaip.net
http://joind.in/talk/view/4481