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
azisaka
March 04, 2013
Technology
7
170
API Design
A keynote made for Papaya Ventures explaining the main points when developing an API.
azisaka
March 04, 2013
Tweet
Share
More Decks by azisaka
See All by azisaka
SASS for fun and profit
azisaka
3
140
Omniauth - Basic and principles
azisaka
1
71
Other Decks in Technology
See All in Technology
現代CSSフレームワークの内部実装とその仕組み
poteboy
8
3.7k
オーナーシップを持つ領域を明確にする
konifar
13
3.2k
Azure犬駆動開発の記録/GlobalAzureFukuoka2024_20240420
nina01
1
220
Cloud Native Java with Spring Boot (CNCF Aarhus, April 2024)
thomasvitale
1
180
LayerXにおけるLLMプロダクト開発の今までとこれから
layerx
PRO
1
430
MLOpsの「壁」を乗り越える、LINEヤフーの Data Quality as Code
lycorptech_jp
PRO
5
540
Android Target SDK 35 (Android 15) 対応の概要
akkie76
0
110
非同期推論システムによるコスト削減と信頼性向上
koki_nishihara
0
270
ゼロから始めるVue.jsコミュニティ貢献 / first-vuejs-community-contribution-link-and-motivation
lmi
1
130
FrontDoorとWebAppsを組み合わせた際のリダイレクト処理の注意点
kenichirokimura
1
590
生産性向上チームの紹介
cybozuinsideout
PRO
1
880
開発生産性大幅アップ!Postman VS Code拡張機能
nagix
2
440
Featured
See All Featured
Bash Introduction
62gerente
604
210k
Designing with Data
zakiwarfel
96
4.8k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
6.9k
Why Our Code Smells
bkeepers
PRO
331
56k
Designing Experiences People Love
moore
136
23k
The Illustrated Children's Guide to Kubernetes
chrisshort
31
46k
Web development in the modern age
philhawksworth
202
10k
For a Future-Friendly Web
brad_frost
172
9k
The Mythical Team-Month
searls
216
42k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
17
1.4k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
227
16k
How GitHub Uses GitHub to Build GitHub
holman
468
290k
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 :)