Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
restkiss: Make REST simple again
Search
Bruno Marques
October 18, 2016
Programming
68
0
Share
restkiss: Make REST simple again
Lightning talk apresentada na Python Brasil [12], em Florianópolis/SC.
Bruno Marques
October 18, 2016
Other Decks in Programming
See All in Programming
Vibe NLP for Applied NLP
inesmontani
PRO
0
490
YJITとZJITにはイカなる違いがあるのか?
nakiym
0
250
JOAI2026 1st solution - heron0519 -
heron0519
0
150
Going Multiplatform with Your Android App (Android Makers 2026)
zsmb
2
450
瑠璃の宝石に学ぶ技術の声の聴き方 / 【劇場版】アニメから得た学びを発表会2026 #エンジニアニメ
mazrean
0
290
「話せることがない」を乗り越える 〜日常業務から登壇テーマをつくる思考法〜
shoheimitani
4
860
Oxlintとeslint-plugin-react-hooks 明日から始められそう?
t6adev
0
280
アクセシビリティ試験の"その後"を仕組み化する
yuuumiravy
1
180
AIを導入する前にやるべきこと
negima
2
260
NakouPAY説明用
annouim0
0
270
10 Tips of AWS ~Gen AI on AWS~
licux
5
470
事業会社でのセキュリティ長期インターンについて
masachikaura
1
270
Featured
See All Featured
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
160
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.1k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
340
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
220
Measuring & Analyzing Core Web Vitals
bluesmoon
9
810
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
380
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
250
Why Our Code Smells
bkeepers
PRO
340
58k
Transcript
restkiss Make REST simple again
Quem? Bruno Oliveira Marques • Porto Alegre - RS •
1ª PythonBrasil ◦ *clap, clap, clap* • Pythonista, sulista, baixista • Backend @ Crave Food Services • Mestrado em Computação @ UFRGS http://twitter.com/assinales http://twitter.com/DataMarques http://github.com/ElSaico
[email protected]
Às vezes você só precisa de verbos HTTP que falem
JSON
Abordagem tradicional (mágica) 1. Escolher framework full-stack 2. Definir schema
no ORM 3. Definir modelo de autenticação/autorização 4. Criar classe(s) referenciando tudo isso 5. ??? 6. Profit!
E se eu não quiser que o framework tome todas
essas decisões por mim?
E se eu não quiser que o framework tome todas
essas decisões por mim? ¯\_(ツ)_/¯
Com Django class PostResource(DjangoResource): preparer = FieldsPreparer(fields={ 'id': 'id', 'title':
'title', 'author': 'user.username', 'body': 'content', 'posted_on': 'posted_on', }) # GET /api/posts/ def list(self): return Post.objects.all() # GET /api/posts/<pk>/ def detail(self, pk): return Post.objects.get(id=pk) # POST /api/posts/ def create(self): return Post.objects.create( title=self.data['title'], content=self.data['body'] ) ... url(r'posts/$', PostResource.as_list())
Sem Django! class PostResource(FlaskResource): posts = SomePostClass() preparer = FieldsPreparer(fields={
'id': 'id', 'title': 'title', 'author': 'username', 'body': 'content', 'posted_on': 'posted_on', }) # GET /api/posts/ def list(self): return self.posts.get_all() # GET /api/posts/<pk>/ def detail(self, pk): return self.posts.get_by_id(pk) # POST /api/posts/ def create(self): return self.posts.create( title=self.data['title'], content=self.data['body'] ) ... PostResource.add_url_rules(app, rule_prefix='/posts/')
Autenticação def is_authenticated(self): return AuthBackend.stuff_which_returns_a_bool(self.request)
Quero retornar um erro! raise Forbidden({‘message’: ‘This is dangerous knowledge
which could kill you’}) raise NotFound({‘message’: ‘Object not found’}) raise IAmATeapot({‘short’: True, ‘stout’: True})
Quero serializar de outros jeitos! class MultiSerializer(Serializer): def deserialize(self, body):
if self.request.GET.get('fmt') == 'yaml': return yaml.safe_load(body) else: return json.load(body) def serialize(self, data): if self.request.GET.get('fmt') == 'yaml': return yaml.dump(body) else: return json.dumps(body) class PostResource(Resource): serializer = MultiSerializer
Obrigado! pip install restkiss http://restkiss.readthedocs.io/