31. Recursos :: URLs + Verbos HTTP
Interface Uniforme
GET http://api.piaz.com.br/ufoapi/v1/casos/1
POST http://api.piaz.com.br/ufoapi/v1/casos/1
PUT http://api.piaz.com.br/ufoapi/v1/casos/1
DELETE http://api.piaz.com.br/ufoapi/v1/casos/1
HEAD http://api.piaz.com.br/ufoapi/v1/casos/1
Recursos são substantivos
Prefira o plural ao singular
2 URLs por recurso
32. Manipulação dos recursos através de suas representações
Interface Uniforme
GET http://api.piaz.com.br/ufoapi/v1/casos/1
39. INSTALAÇÃO / Requisitos mínimos
○ Webserver (apache, nginx, iis)
○ PHP >= 5.2.4
○ gettext
○ XMLWriter
○ PEAR
○ 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
40. git clone git://github.com/frapi/frapi.git
git clone git://github.com/zaip/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
INSTALAÇÃO / Obtendo o software
41. Interface administrativa API Pública
Camadas de interação
● Zend Framework
● Actions e Errors
● Autenticação
● Documentação
● Ambiente de testes
● Produção
● PHP
● Cache
● Request
● Response
Interface CLI
● Admin via terminal
42. <VirtualHost *:80>
ServerName admin.frapi
DirectoryIndex index.php
ServerAdmin admin@api.frapi
# 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 admin@api.frapi
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_PATH
chmod 775 FRAPI_PATH/src/frapi/custom/Action
chmod 775 FRAPI_PATH/src/frapi/custom/Config/
chmod 664 FRAPI_PATH/src/frapi/custom/Config/*.xml
43. Dá pra instalar sem 2 vhosts?
http://www.felipemarques.com.br/tag/alex-piaz/
SIM
49. UFO API
Modelo
Mensagens de erro (Not found [404] / NO PUT/DELETE/POST [405] )
2 URLs === 2 actions
//api.piaz.com.br/ufoapi/v1/casos (GET POST)
//api.piaz.com.br/ufoapi/v1/casos/{id} (GET PUT DELETE)
Complexidade vai na Query String
//api.piaz.com.br/ufoapi/v1/casos?pais=Brasil
Principais casos da Ufologia Mundial em ReSTFul!
50. UFO APIPrincipais casos da Ufologia Mundial REST!
Custom_Model_Caso()
getCasos()
getCaso($id)
getCasosPorPais($pais)
insertCaso($data)
updateCaso($id,$data)
deleteCaso($id)
52. UFO APIPrincipais casos da Ufologia Mundial em ReSTFul!
Métodos disponibilizados pelo FRAPI
executeGet()
executePost()
executePut()
executeDelete()
executeHead()http://frapi.github.com/developing/coding-actions.html
53. UFO APIPrincipais casos da Ufologia Mundial em ReSTFul!
Mensagens de erro
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
64. Utilidades
implementing-rest
Exploring the implementation aspects of the REST architectural style.
https://code.google.com/p/implementing-rest/
PostMan - Rest Client para o Chrome
https://chrome.google.com/webstore/detail/fdmmgilgnpjigdojojpjoooidkmcomcm
Tese do Roy Fieldling (nascimento do ReST)
http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm
Richardson Maturity Model
http://martinfowler.com/articles/richardsonMaturityModel.html
Swagger (Documentação para sua API)
https://developers.helloreverb.com/swagger/
API Best Pratices
http://apigee.com/about/api-best-practices
HTTP (RFC 2616)
http://tools.ietf.org/html/rfc2616