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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Bruno Marques
October 18, 2016
Programming
69
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
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
160
Webフレームワークの ベンチマークについて
yusukebe
0
170
Inside Stream API
skrb
1
740
Claspは野良GASの夢をみるか
takter00
0
200
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.3k
Vite+ Unified Toolchain for the Web
naokihaba
0
320
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
880
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
270
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.1k
OSもどきOS
arkw
0
570
net-httpのHTTP/2対応について
naruse
0
500
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
400
Featured
See All Featured
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
600
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
420
Measuring & Analyzing Core Web Vitals
bluesmoon
9
870
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Test your architecture with Archunit
thirion
1
2.3k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
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/