DJANGO-REST-FRAMEWORK
AWESOME WEB-BROWSABLE WEB APIS
por Filipe Ximenes e Fernando Rocha
Developer @ thinkr
Apaixonado por Python
Entusiasta de Software Livre
Interessado em web e infraestrutura.
THINKR
Fundador da Vinta
Desenvolvedor Web
Apaixonado por aprender
Fã de comunidades de Sofware Livre
Curioso de empreendedorismo
DJANGO-REST-FRAMEWORK

AWESOME WEB-BROWSABLE WEB

API'S
API (APPLICATION PROGRAMMING INTERFACE)
Uma Interface de Programação de Aplicação especifica como
certos componentes de software devem interagir uns com os
outros.
DJANGO-

REST-FRAMEWORK

AWESOME WEB-BROWSABLE WEB API'S
MÉTODOS HTTP
GET
POST
MÉTODOS HTTP (RFC 2616)
GET
POST
HEAD
PUT
DELETE
OPTIONS
TRACE
CONNECT
RESTFULL API
Utiliza todo o potencial do HTTP para servir recursos através de
métodos (verbos)
EXEMPLO
/user_list
/user_create
/user?id=xxx
/user_edit?id=xxx
/user_delete?id=xxx
EXEMPLO RESTFULL
GET
POST
GET
PUT
DELETE

/user
/user
/user/id
/user/id
/user/id
DJANGO-REST-FRAMEWORK
AWESOME WEB-BROWSABLE WEB API'S
DJANGO-REST-FRAMEWORK
É um conjunto de ferramentas construidas a partir do Django
que facilitam a construção de API's REST
NÚMEROS
Criador
- Tom Christie
Estrelas
- 1592
Forks
- 464
Documentação
UMA VIEW SIMPLES
APIVIEW
fo rs_rmwr.iw ipr AIiw
rm etfaeokves mot PVe
fo rs_rmwr.epneipr Rsos
rm etfaeokrsos mot epne
fo rs_rmwr.edrr ipr JORnee
rm etfaeokrnees mot SNedrr
casPlsrneVe(PVe)
ls aetatsiwAIiw:
rnee_lse =(SNedrr)
edrrcass
JORnee,
dfgtsl,rqet *rs *kag)
e e(ef eus, ag, *wrs:
dt =['oe:'iie,
aa
{nm' Flp'
'iae:'eie,
cdd' Rcf'
'mrs' 'it',
epea: Vna}
{nm' 'enno,
'oe: Frad'
'iae:'eie,
cdd' Rcf'
'mrs' 'hnr}
epea: Tik']
rtr Rsos(aa
eun epnedt)
RESPOSTA
HT/. 20O
TP11 0 K
CnetTp:plcto/sn
otn-yeapiainjo
[
{
cdd:"eie,
iae Rcf"
epea "it"
mrs: Vna,
nm:"iie
oe Flp"
}
,
{
cdd:"eie,
iae Rcf"
epea "hnr,
mrs: Tik"
nm:"enno
oe Frad"
}
]
RENDERIZADORES
DA PYTHON PARA TEXTO
JORnee
SNedrr
UioeSNedrr
ncdJORnee
JOPedrr
SNRnee
YMRnee
ALedrr
XLedrr
MRnee
TmltHMRnee
epaeTLedrr
SaiHMRnee
ttcTLedrr
HMFrRnee
TLomedrr
BosbePRnee
rwalAIedrr
#aeedrr
BsRnee
JSON
rnee_lse =(SNedrr)
edrrcass
JORnee,
HT/. 20O
TP11 0 K
CnetTp:plcto/sn
otn-yeapiainjo
[
{
"oe:"iie,
nm" Flp"
"iae:"eie,
cdd" Rcf"
"mrs" "it"
epea: Vna
}
,
{
"oe:"enno,
nm" Frad"
"iae:"eie,
cdd" Rcf"
"mrs" "hnr
epea: Tik"
}
]
XML
rnee_lse =(MRnee,
edrrcass
XLedrr)
HT/. 20O
TP11 0 K
CnetTp:plcto/m
otn-yeapiainxl
<xlvrin"."ecdn=uf8?
?m eso=10 noig"t-">
<ot
ro>
<itie>
ls-tm
<iaeRcf<cdd>
cdd>eie/iae
<mrs>it<epea
epeaVna/mrs>
<oeFlp<nm>
nm>iie/oe
<ls-tm
/itie>
<itie>
ls-tm
<iaeRcf<cdd>
cdd>eie/iae
<mrs>hnr/mrs>
epeaTik<epea
<oeFrad<nm>
nm>enno/oe
<ls-tm
/itie>
<ro>
/ot
BROWSABLE API
rnee_lse =(rwalAIedrr)
edrrcass
BosbePRnee,
PARSERS
DE TEXTO PARA PYTHON
JOPre
SNasr
YMPre
ALasr
XLasr
MPre
FrPre
omasr
Mliatasr
utPrPre
FlUlaPre
iepodasr
#aeasr
BsPre
AUTENTICAÇÃO
BASTA DECLARAR
fo rs_rmwr.iw ipr AIiw
rm etfaeokves mot PVe
fo rs_rmwr.epneipr Rsos
rm etfaeokrsos mot epne
fo rs_rmwr.uhniainipr Ssinuhniain 
rm etfaeokatetcto mot esoAtetcto,
Tknuhniain
oeAtetcto
casPlsrneVe(PVe)
ls aetatsiwAIiw:
atetcto_lse =(esoAtetcto,
uhniaincass
Ssinuhniain
Tknuhniain)
oeAtetcto,
priso_lse =(suhniae,
emsincass
IAtetctd)
dfgtsl,rqet *rs *kag)
e e(ef eus, ag, *wrs:
dt =['oe:'iie,
aa
{nm' Flp'
'iae:'eie,
cdd' Rcf'
'mrs' 'it',
epea: Vna}
{nm' 'enno,
'oe: Frad'
'iae:'eie,
cdd' Rcf'
'mrs' 'hnr}
epea: Tik']
rtr Rsos(aa
eun epnedt)
FALHA NA AUTENTICAÇÃO
HT/. 41O
TP10 0 K

HTTP_401_UNAUTHORIZED
HT/. 43O
TP10 0 K

HTTP_403_FORBIDDEN
AUTENTICAÇÃO PLUGÁVEL
Bscuhniain
aiAtetcto
Tknuhniain
oeAtetcto
Ssinuhniain
esoAtetcto
Ouhuhniain
AtAtetcto
OuhAtetcto
At2uhniain
#aeuhniain
BsAtetcto
DEFININDO DEFAULT NO SETTINGS
RS_RMWR ={
ETFAEOK
'EAL_UHNIAINCASS:(
DFUTATETCTO_LSE'
'etfaeokatetcto.esoAtetcto'
rs_rmwr.uhniainSsinuhniain,
'etfaeokatetcto.oeAtetcto'
rs_rmwr.uhniainTknuhniain
)
,
}
SIMPLIFICANDO A VIEW
GENERICAPIVIEW
models.py
fo dag.bipr mdl
rm jnod mot oes
casSekrmdl.oe)
ls pae(oesMdl:
nm =mdl.hril('oe,mxlnt=0
ae
oesCaFeduNm' a_egh5)
ct =mdl.hril('iae,mxlnt=0
iy
oesCaFeduCdd' a_egh5)
cmay=mdl.hril('mrs' mxlnt=0
opn
oesCaFeduEpea, a_egh5)
poe=mdl.hril('eeoe,mxlnt=2 bakTu)
hn
oesCaFeduTlfn' a_egh1, ln=re

views.py
fo rs_rmwr ipr gnrc
rm etfaeok mot eeis
fo .oesipr Sekr
rm mdl mot pae
casSekritgnrc.itraePVe)
ls paeLs(eeisLsCetAIiw:
''
'
Edon qerpeet alsad plsrne,eprieqenvs
npit u ersna
it e aetats
emt u oo
plsrne sjmcdsrds
aetats ea aatao.
''
'
mdl=Sekr
oe
pae
GET /SPEAKERS/
HT/. 20O
TP10 0 K
Alw GT PS,HA,OTOS
lo: E, OT ED PIN
CnetTp:apiainjo;castuf8
otn-ye plcto/sn hre=t[
{
"iy:"eie,
ct" Rcf"
"opn" "hnr,
cmay: Tik"
"d:1
i" ,
"ae:"ennoRca,
nm" Frad oh"
"hn" "2468
poe: 1357"
}
,
{
"iy:"eie,
ct" Rcf"
"opn" "it"
cmay: Vna,
"d:2
i" ,
"ae:"iieXmns,
nm" Flp iee"
"hn" "2468
poe: 1357"
}
]
POST /SPEAKERS/
request
{
}

response
HT/. 40BDRQET
TP10 0 A EUS
Alw GT PS,HA,OTOS
lo: E, OT ED PIN
CnetTp:apiainjo;castuf8
otn-ye plcto/sn hre=t{
"iy:[
ct"
"hsfedi rqie.
Ti il s eurd"
]
,
"opn" [
cmay:
"hsfedi rqie.
Ti il s eurd"
]
,
"ae:[
nm"
"hsfedi rqie.
Ti il s eurd"
]
}
POST /SPEAKERS/
request
{nm' 'ae' 'opn' 'ND,'hn' '111}
'ae: Dkr, cmay: IT' poe: 333'

response
HT/. 21CETD
TP10 0 RAE
Alw GT PS,HA,OTOS
lo: E, OT ED PIN
CnetTp:apiainjo;castuf8
otn-ye plcto/sn hre=t{
"iy:"eie,
ct" Rcf"
"opn" "ND,
cmay: IT"
"d:3
i" ,
"ae:"ae"
nm" Dkr
"hn" "111
poe: 333"
}
GENERIC VIEWS
CetAIiw
raePVe
LsAIiw
itPVe
RtivAIiw
ereePVe
DsryPVe
etoAIiw
UdtAIiw
paePVe
LsCetAIiw
itraePVe
RtivUdtAIiw
ereepaePVe
RtivDsryPVe
ereeetoAIiw
RtivUdtDsryPVe
ereepaeetoAIiw
CUSTOMIZANDO OS DADOS
(SERIALIZADORES)
SERIALIZADORES
Converte objetos de Python para listas e dicionários
Converte dicionários e listas para objetos de Python
Semelhante a API de forms do Django
DEFININDO CAMPOS
serializers.py
fo rs_rmwr ipr sraies
rm etfaeok mot eilzr
fo .oesipr Sekr
rm mdl mot pae
casSekreilzrsraiesMdleilzr:
ls paeSraie(eilzr.oeSraie)
casMt:
ls ea
mdl=Sekr
oe
pae
fed =(nm' 'iy,'opn'
ils
'ae, ct' cmay)
UTILIZANDO GENERIC VIEWS
serializers.py
fo rs_rmwr ipr sraies
rm etfaeok mot eilzr
fo .oesipr Sekr
rm mdl mot pae
casSekreilzrsraiesMdleilzr:
ls paeSraie(eilzr.oeSraie)
casMt:
ls ea
mdl=Sekr
oe
pae
fed =(nm' 'iy,'opn'
ils
'ae, ct' cmay)

views.py
fo rs_rmwr ipr gnrc
rm etfaeok mot eeis
fo .oesipr Sekr
rm mdl mot pae
casSekritgnrc.itraePVe)
ls paeLs(eeisLsCetAIiw:
''
'
Edon qerpeet alsad plsrne,eprieqenvs
npit u ersna
it e aetats
emt u oo
plsrne sjmcdsrds
aetats ea aatao.
''
'
mdl=Sekr
oe
pae
sraie_ls =Sekreilzr
eilzrcas
paeSraie
GET /SPEAKERS/
HT/. 20O
TP10 0 K
Alw GT PS,HA,OTOS
lo: E, OT ED PIN
CnetTp:apiainjo;castuf8
otn-ye plcto/sn hre=t[
{
"iy:"eie,
ct" Rcf"
"opn" "hnr,
cmay: tik"
"ae:"ennoRca"
nm" Frad oh,
}
,
{
"iy:"eie,
ct" Rcf"
"opn" "it"
cmay: Vna,
"ae:"iieXmns"
nm" Flp iee,
}
,
{
"iy:"eie,
ct" Rcf"
"opn" "ND,
cmay: IT"
"ae:"ae,
nm" Dkr"
}
]
COMO FUNCIONA?
views.py
fo rs_rmwr ipr gnrc
rm etfaeok mot eeis
fo rs_rmwr.epneipr Rsos
rm etfaeokrsos mot epne
fo .oesipr Sekr
rm mdl mot pae
casSekritgnrc.PVe)
ls paeLs(eeisAIiw:
''
'
Edon qerpeet alsad plsrne,eprieqenvs
npit u ersna
it e aetats
emt u oo
plsrne sjmcdsrds
aetats ea aatao.
''
'
dfps(ef rqet:
e otsl, eus)
sraie =Sekreilzrdt=eus.AA
eilzr
paeSraie(aarqetDT)
i sraie.svld)
f eilzri_ai(:
sraie.ae)
eilzrsv(
rtr Rsos(eilzrdt,sau=0)
eun epnesraie.aa tts21
rtr Rsos(eilzrero,sau=0)
eun epnesraie.rrs tts40
VALIDAÇÃO
serializers.py
fo rs_rmwr ipr sraies
rm etfaeok mot eilzr
fo .oesipr Sekr
rm mdl mot pae
casSekreilzrsraiesMdleilzr:
ls paeSraie(eilzr.oeSraie)
casMt:
ls ea
mdl=Sekr
oe
pae
fed =(nm' 'iy,'opn'
ils
'ae, ct' cmay)
dfvldt_aesl,ats suc)
e aiaenm(ef tr, ore:
i lnatssuc]slt) <2
f e(tr[ore.pi()
:
riesraiesVldtoErruIfreonm esbeoe)
as eilzr.aiainro('nom
oe
ornm'
rtr ats
eun tr
POST /SPEAKERS/
request
{nm' '' 'iy:'eie,'opn' 'et}
'ae: a, ct' rcf' cmay: ts'

response
HT/. 40BDRQET
TP10 0 A EUS
Alw GT PS,HA,OTOS
lo: E, OT ED PIN
CnetTp:apiainjo;castuf8
otn-ye plcto/sn hre=t{
"ae:[
nm"
"nom onm esbeoe
Ifre
oe
ornm"
]
}
GET /SPEAKERS/
HT/. 20O
TP10 0 K
Alw GT PS,HA,OTOS
lo: E, OT ED PIN
CnetTp:apiainjo;castuf8
otn-ye plcto/sn hre=t[
{
"iy:"eie,
ct" Rcf"
"opn" "HNR,
cmay: TIK"
"ae:"ennoRca"
nm" Frad oh,
}
,
{
"iy:"eie,
ct" Rcf"
"opn" "IT"
cmay: VNA,
"ae:"iieXmns"
nm" Flp iee,
}
,
{
"iy:"eie,
ct" Rcf"
"opn" "ND,
cmay: IT"
"ae:"ae,
nm" Dkr"
}
,
]
VIEWSETS
VIEWSET
views.py
fo rs_rmwr ipr vest
rm etfaeok mot iwes
fo .oesipr Sekr
rm mdl mot pae
casSekriwe(iwesMdliwe)
ls paeVeStvest.oeVeSt:
''
'
Edon pr vsaie eeia isâca d Sekr
npit aa iulzr
dtr ntnis e pae
''
'
sraie_ls =UeSraie
eilzrcas
sreilzr
qeye =Sekrojcsal)
urst
pae.bet.l(
FILIPE XIMENES
github.com/filipeximenes
twitter.com/xima

FERNANDO ROCHA
livingintheshell.com
github.com/fernandogrd
twitter.com/fernandogrd

More Related Content

PDF
Silabus OSN SMP 2016
PDF
내 친구를 소개합니다
PDF
Κώδικες Ορθής Ελαιοκομικής Πρακτικής
PDF
42 jembatan
PDF
PDF
Reviwer in seminar education
PDF
Img 20160615 0001
PDF
RMAT deploma in ENG
Silabus OSN SMP 2016
내 친구를 소개합니다
Κώδικες Ορθής Ελαιοκομικής Πρακτικής
42 jembatan
Reviwer in seminar education
Img 20160615 0001
RMAT deploma in ENG

What's hot (13)

PDF
Bachelor's degree
PDF
certificates - Copy
PDF
8 vi atlas
PDF
diseño de losas en dos direcciones
PDF
KL Innovation
PDF
Electricity new 2014.PDF
PDF
baubec-limba-turca-fara-profesor
PDF
Fernando alvarado 8 228-414-problema nº3 examen -1
PDF
merged_document
PPT
Основы Reverse Engineering
PDF
Mapa conceptual mic
PDF
Travesia san jose
Bachelor's degree
certificates - Copy
8 vi atlas
diseño de losas en dos direcciones
KL Innovation
Electricity new 2014.PDF
baubec-limba-turca-fara-profesor
Fernando alvarado 8 228-414-problema nº3 examen -1
merged_document
Основы Reverse Engineering
Mapa conceptual mic
Travesia san jose
Ad

Viewers also liked (17)

PDF
Boas práticas de django
PDF
Django rest framework tips and tricks
PDF
Introduction to Django REST Framework, an easy way to build REST framework in...
PDF
API Design & Security in django
PDF
O que é esse tal de rest? [PyBR2016]
PPTX
Implementation of RSA Algorithm for Speech Data Encryption and Decryption
PDF
Como fazer boas libs
PPTX
Парсер: что? зачем? как?
PDF
Como um verdadeiro sistema REST funciona: arquitetura e performance na Abril
PPTX
django-and-postgresql
PDF
Junho 2016 - Django - A sua cápsula de soluções web em python
PDF
Django Rest Framework and React and Redux, Oh My!
PDF
Framework Battle: Django vs Flask vs Chalice
PPTX
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
PDF
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
PDF
Django Best Practices
PDF
Create responsive websites with Django, REST and AngularJS
Boas práticas de django
Django rest framework tips and tricks
Introduction to Django REST Framework, an easy way to build REST framework in...
API Design & Security in django
O que é esse tal de rest? [PyBR2016]
Implementation of RSA Algorithm for Speech Data Encryption and Decryption
Como fazer boas libs
Парсер: что? зачем? как?
Como um verdadeiro sistema REST funciona: arquitetura e performance na Abril
django-and-postgresql
Junho 2016 - Django - A sua cápsula de soluções web em python
Django Rest Framework and React and Redux, Oh My!
Framework Battle: Django vs Flask vs Chalice
Learning python with flask (PyLadies Malaysia 2017 Workshop #1)
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Django Best Practices
Create responsive websites with Django, REST and AngularJS
Ad

DJANGO-REST-FRAMEWORK: AWESOME WEB-BROWSABLE WEB APIS