Restful Web Services Frap i

37
RESTFUL webservicesConstruindo Apis Alex Piaz http://joind.in/talk/view /4481

description

Apresentação sobre Restful Webservices

Transcript of Restful Web Services Frap i

Page 1: Restful Web Services Frap i

RESTFUL webservicesConstruindo Apis

Alex Piaz

http://joind.in/talk/view/4481

Page 2: Restful Web Services Frap i

Agenda

Eu

Webservices

API's

Frapi

Demo

Page 3: Restful Web Services Frap i

? quem sou eu ?

Page 4: Restful Web Services Frap i

Mercantólogo por formação, desenvolvedor por paixão!

Ativista por consciência!

Page 5: Restful Web Services Frap i

Há 15 anos nas interwebs...

Page 6: Restful Web Services Frap i

Há 15 anos nas interwebs...

Page 7: Restful Web Services Frap i

Há 15 anos nas interwebs...

http://web.archive.org/web/19961223175947/http://uol.com.br/

1996

Page 8: Restful Web Services Frap i

Há 12 anos...

1998

Page 9: Restful Web Services Frap i

Há 7 anos...

1998

Ah! Cem mil dólares! Mulheres, automóvel. Mulheres! Iate, mulheres, mansões, mulheres, ah!

Page 10: Restful Web Services Frap i

Há 6 anos...

1998

Page 11: Restful Web Services Frap i

Webservices

"a software system designed to support interoperable machine-to-machine interaction over a network"

http://www.w3.org/TR/ws-arch/#whatis

Page 12: Restful Web Services Frap i

RPC

HTTP, SMTP ,FTP ,etc

getUser()

XML

ReST

HTTP

http://servidor/user/{user}

múltiplas saídas

Page 13: Restful Web Services Frap i

É só fazer um "XML" que resolve....

Page 14: Restful Web Services Frap i

Na vida real é um pouco mais complicado....

Autenticação

Documentação

Diferentes formatos de saída

Tratamento de erros

Page 15: Restful Web Services Frap i

E o FRAPI entra em cena!

http://getfrapi.com

Page 16: Restful Web Services Frap i

FRAMEWORK API

Page 17: Restful Web Services Frap i

Interface administrativa

API Pública

Camadas de interação

• Zend Framework• Actions e Errors• Autenticação• Documentação• Ambiente de testes

• PHP Puro• Cache

Page 18: Restful Web Services Frap i

INSTALAÇÃO

Page 19: Restful Web Services Frap i

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

Page 20: Restful Web Services Frap i

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

Page 21: Restful Web Services Frap i

<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

Page 22: Restful Web Services Frap i

INSTALAÇÃO / Finalizando

Page 23: Restful Web Services Frap i
Page 24: Restful Web Services Frap i
Page 25: Restful Web Services Frap i

UFO API

Principais casos da Ufologia Mundial em ReSTFul!

CRUD

Page 26: Restful Web Services Frap i

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!

Page 27: Restful Web Services Frap i

UFO API

Principais casos da Ufologia Mundial em ReSTFul!

Mensagens de erro

http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Page 28: Restful Web Services Frap i

UFO API

Principais casos da Ufologia Mundial em ReSTFul!

Custom_Model_Caso()

getCasos()

getCaso($id)

insertCaso($data)

updateCaso($id,$data)

deleteCaso($id)

Page 29: Restful Web Services Frap i
Page 30: Restful Web Services Frap i

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

Page 31: Restful Web Services Frap i

FRAPI_PATH/src/frapi/custom/Action

Page 32: Restful Web Services Frap i

UFO API

Principais casos da Ufologia Mundial em ReSTFul!

ListaCasos - http://ufo-api.piaz.com.br/casos (GET)

Page 33: Restful Web Services Frap i

UFO API

Principais casos da Ufologia Mundial em ReSTFul!

InsereCaso - http://ufo-api.piaz.com.br/caso (POST)

Page 34: Restful Web Services Frap i

UFO API

Principais casos da Ufologia Mundial em ReSTFul!

Caso - http://ufo-api.piaz.com.br/caso/{id} (GET PUT DELETE)

Page 35: Restful Web Services Frap i

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

Page 36: Restful Web Services Frap i
Page 37: Restful Web Services Frap i

Alex Piaz (@zaip)[email protected]://www.zaip.net

http://joind.in/talk/view/4481