$30 off During Our Annual Pro Sale. View Details »
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
0
66
restkiss: Make REST simple again
Lightning talk apresentada na Python Brasil [12], em Florianópolis/SC.
Bruno Marques
October 18, 2016
Tweet
Share
Other Decks in Programming
See All in Programming
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
7
2.3k
令和最新版Android Studioで化石デバイス向けアプリを作る
arkw
0
440
Patterns of Patterns
denyspoltorak
0
320
Jetpack XR SDKから紐解くAndroid XR開発と技術選定のヒント / about-androidxr-and-jetpack-xr-sdk
drumath2237
1
190
[AtCoder Conference 2025] LLMを使った業務AHCの上⼿な解き⽅
terryu16
6
720
TestingOsaka6_Ozono
o3
0
170
Grafana:建立系統全知視角的捷徑
blueswen
0
200
チームをチームにするEM
hitode909
0
370
著者と進める!『AIと個人開発したくなったらまずCursorで要件定義だ!』
yasunacoffee
0
160
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
39
26k
バックエンドエンジニアによる Amebaブログ K8s 基盤への CronJobの導入・運用経験
sunabig
0
170
AIエンジニアリングのご紹介 / Introduction to AI Engineering
rkaga
8
3.3k
Featured
See All Featured
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
170
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
69
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
Site-Speed That Sticks
csswizardry
13
1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.1k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
410
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Fireside Chat
paigeccino
41
3.8k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.3k
Crafting Experiences
bethany
0
22
Heart Work Chapter 1 - Part 1
lfama
PRO
3
35k
Darren the Foodie - Storyboard
khoart
PRO
0
1.9k
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/