Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
restkiss: Make REST simple again
Search
Bruno Marques
October 18, 2016
Programming
74
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
110
AI × TiDD / 2026.09.05 Redmine 大阪
tokudiro
1
170
Heart of Swift Concurrency
koher
0
800
個人開発基盤をまるごとCloudflareに引っ越して爆速で総合的体験を向上させた話
tinykitten
0
190
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
120
GKE で Pod の見方を変えたら、スケールアウト時の挙動を真に捉えられた話
stkk
0
120
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
140
AIを上手に使っていこうとしたら越境せざるを得なくなった話 〜実践1年で見えた境界を越えなければならない理由と進め方〜 / Crossing borders with AI
tomoyakitaura
4
1.2k
Webの地図
yosuke_furukawa
PRO
6
4.5k
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
120
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
140
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
580
Featured
See All Featured
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
300
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
Side Projects
sachag
456
43k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
Paper Plane (Part 1)
katiecoart
PRO
2
11k
My Coaching Mixtape
mlcsv
0
310
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
610
4 Signs Your Business is Dying
shpigford
187
23k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1k
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/