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
API Design
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
azisaka
March 04, 2013
Technology
190
7
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
API Design
A keynote made for Papaya Ventures explaining the main points when developing an API.
azisaka
March 04, 2013
More Decks by azisaka
See All by azisaka
SASS for fun and profit
azisaka
3
150
Omniauth - Basic and principles
azisaka
1
84
Other Decks in Technology
See All in Technology
Text-to-SQLをAgentCoreで実現し、生成されるSQLの精度を定量的に評価する
yakumo
2
790
CSに"SLO"は要らない、経営層に"99.9%"は伝わらない - SREを全社に"翻訳"する3原則
cscengineer
PRO
1
4.3k
Keeping applications secure by evolving OAuth 2.0 and OpenID Connect
ahus1
PRO
1
160
脱金融のフューチャー・デザイン / Future Design Beyond Finance
ks91
PRO
0
140
人を動かすのは時間ではなく、納得感 〜新任EMが入社3ヶ月、組織を2回変えた話〜
kakehashi
PRO
3
200
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
15
110k
DMM.com 購入改善推進チーム におけるCodeRabbitを用いた レビューフロー改善の一例
ysknsid25
2
580
ZOZOTOWNの進化と信頼性を両立する負荷試験
zozotech
PRO
2
160
ポストモーテム! DDoSからサイトは守れた。 でもビジネスは守れなかった。
bengo4com
0
2.5k
“全部コピーしない”ファイルデータの活用 : — FSx for ONTAP × S3 Tables × Icebergで作るメタデータカタログ
yoshiki0705
0
680
はじめてのWDM
miyukichi_ospf
1
140
環境凍結という Toil を倒す -セルフサービス型 Ephemeral テスト環境の 設計と実践
shirouz
1
2.1k
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
970
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
260
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
380
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
220
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Practical Orchestrator
shlominoach
191
11k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
600
Skip the Path - Find Your Career Trail
mkilby
1
160
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
How to build a perfect <img>
jonoalderson
1
5.8k
Transcript
por que você deveria se importar? API design
Como enviar dados para a nuvem?
API Application Programming Interface Fácil de usar Rápida Leve JSON
Construindo uma API
Representational State Transfer REST
Arquitetura DISTRIBUÍDA
Representação de Entidades /posts/1.json /posts/1/comments.json /posts/1/likes.json
HTTP METHOD ACTION VERBO SUBSTANTIVO GET DELETE POST PUT /posts
/posts /posts/1 /posts/1
USE Substantivos ao inves de verbos
verbos criam uma API prolixa GET /listarPosts.json POST /criarPost.json GET
/visualizarPost.json?id=1
Se aproveite dos HTTP methods GET /posts.json POST /posts.json GET
/posts/1.json PUT /posts/1.json DELETE /posts/1.json
Sempre plural, nunca singular
ENdpoints no plural são intuitivos GET /posts GET /posts/1 PUT
/posts/1 POST /posts
Substantivos concretos, nunca abstratos
Endpoints devem ter significado GET /items GET /products GET /users
GET /assets Ruim Bom
RELACIONE RECURSOS DE FORMA SIMPLES
Endpoints auto-explicativos Foto Likes POST /photos/1/likes Categoria Estabelecimentos GET /categories/restaurant/venues
Coloque a complexidade DEPOIS da “?”
filtros e buscas GET /posts?status=draft GET /posts/1/comments?user_id=1 GET /posts?q=something
Resultados devem ser paginados
Indiquem onde o resultado está GET /posts { “posts”: [
{ “id”: 1, title: “Post #1” }, { “id”: 2, title: “Post #2” } ], “page”: 1, “total”: 10, “perPage”: 2 } GET /posts?page=2&perPage=1 { “posts”: [ { “id”: 3, title: “Post #3” }, ], “page”: 2, “total”: 10, “perPage”: 1 }
Retorne dados parcialmente
Reduza o payload GET /posts/1 { “post”: { “id”: 1,
“title”: “Post #1”, “body”: “Post’s body”, “tags”: [“api”, “web”, “http”], “category”: { “name”: “Development” } } } GET /posts/1?fields=id,title { “post”: { “id”: 1, “title”: “Post #1” } }
Retorne erros com significado
Seja claro! POST /posts { “status”: 400, “message”: “O título
não pode ficar em branco” }
Versione sua API
E mantenha ao menos 1 versão GET /v1/posts/1 GET /v2/posts/1
{ “post”: { “id”: 1, “title”: “Post #1”, “content”: “Post’s body” } } } { “post”: { “id”: 1, “title”: “Post #1”, “body”: “Post’s body” } } }
Use um subdomínio
api.seuprojeto.com Escalabilidade independente Controle de cache e CDN independente Organização
Wrap up
APIs podem fazer a diferença durante o desenvolvimento Cuidado com
o Design
A mesma API pode ser core de aplicativos iPhone, Android,
Web e Desktop Colha os frutos
Outros aplicativos podem aumentar o valor do seu produto expandindo
o seu uso Aumente seu evaluation
O caso “Instragram”
None
None
None
None
None
Obrigado :)