CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 1 / 81
galvao.eti.br
v 1.2.0 - 2024-12-07
APIs
do jeito certo
Slide 2
Slide 2 text
Atua há 30 anos no Mercado de TI:
Programador (> 25), Professor / Palestrante (> 20) e Consultor (> 25)
Engenheiro de Software Sênior / Tech Lead
Professor Convidado (Especialista) de Pós-Graduação (PR e SC)
Diretor, ConFLOSS, NodeConBR e PHP Conference Brasil
Evangelista e Contribuidor para a Linguagem PHP
Evangelista e Contribuidor para o Laminas Project
Primeiro Brasileiro a se tornar Postman Supernova
Presidente da ABRAPHP – Associação Brasileira de Profissionais PHP
Apaixonado por Backend, APIs, Qualidade, Segurança e Software Livre
galvao.eti.br
galvao.eti.br
Meu nome é Galvão
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/2024 – v0.2.0 – Slide 2 / 81
Slide 3
Slide 3 text
galvao.eti.br
Objetivo
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 3 / 81
Apresentar um apanhado geral sobre APIs, incluindo:
●
Design-First
●
OpenAPI Specification
●
Ciclo de desenvolvimento
●
ReST(ful)
●
e instrumental.
Slide 4
Slide 4 text
APIs...?
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 4 / 81
Slide 5
Slide 5 text
APIs FTW!
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 5 / 81
APIs?
Slide 6
Slide 6 text
APIs FTW!
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 6 / 81
APIs?
strlen( string $str )
→
int
Slide 7
Slide 7 text
APIs FTW!
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 7 / 81
APIs?
strlen( string $str )
→
int
ponto de acesso
Slide 8
Slide 8 text
APIs FTW!
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 8 / 81
APIs?
strlen( string $str )
→
int
ponto de acesso informação
Slide 9
Slide 9 text
APIs FTW!
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 9 / 81
APIs?
strlen( string $str )
→
int
ponto de acesso informação resultado
Slide 10
Slide 10 text
APIs FTW!
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 10 / 81
APIs?
strlen( string $str )
→
int
https://whatevers/product/1109
→
{...}
Slide 11
Slide 11 text
APIs FTW!
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 11 / 81
APIs?
strlen( string $str )
→
int
https://whatevers/product/1109
→
{...}
ponto de acesso
Slide 12
Slide 12 text
APIs FTW!
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 12 / 81
APIs?
strlen( string $str )
→
int
https://whatevers/product/1109
→
{...}
ponto de acesso informação
Slide 13
Slide 13 text
APIs FTW!
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 13 / 81
APIs?
strlen( string $str )
→
int
https://whatevers/product/1109
→
{...}
ponto de acesso informação resultado
Slide 14
Slide 14 text
Por que toda a aplicação deveria
ser desenvolvida como uma API?
galvao.eti.br
Por que APIs
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 14 / 81
Slide 15
Slide 15 text
Por que toda a aplicação deveria ser desenvolvida como uma API?
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 15 / 81
Por que APIs
Slide 16
Slide 16 text
Por que toda a aplicação deveria ser desenvolvida como uma API?
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 16 / 81
Por que APIs
+ Verdadeira Separação entre Back e Front
Slide 17
Slide 17 text
Por que toda a aplicação deveria ser desenvolvida como uma API?
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 17 / 81
Por que APIs
+ Verdadeira Separação entre Back e Front
+ Agnosticismo de linguagens
Slide 18
Slide 18 text
Por que toda a aplicação deveria ser desenvolvida como uma API?
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 18 / 81
Por que APIs
+ Verdadeira Separação entre Back e Front
+ Agnosticismo de linguagens
+ Otimização de Performance de backend
Slide 19
Slide 19 text
Por que toda a aplicação deveria ser desenvolvida como uma API?
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 19 / 81
Por que APIs
+ Verdadeira Separação entre Back e Front
+ Agnosticismo de linguagens
+ Otimização de Performance de backend
+ Um back*, múltiplos fronts
Slide 20
Slide 20 text
Por que toda a aplicação deveria ser desenvolvida como uma API?
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 20 / 81
Por que APIs
+ Verdadeira Separação entre Back e Front
+ Agnosticismo de linguagens
+ Otimização de Performance de backend
+ Um back*, múltiplos fronts
+ Escalabilidade*
Slide 21
Slide 21 text
Por que toda a aplicação deveria ser desenvolvida como uma API?
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 21 / 81
Por que APIs
+ Verdadeira Separação entre Back e Front
+ Agnosticismo de linguagens
+ Otimização de Performance de backend
+ Um back*, múltiplos fronts
+ Escalabilidade*
* Ou, até mesmo, múltiplos backs e fronts
Slide 22
Slide 22 text
Por que Design-First?
galvao.eti.br
Por que Design-First?
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 22 / 81
Slide 23
Slide 23 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 23 / 81
Por que Design-First?
Slide 24
Slide 24 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 24 / 81
Por que Design-First?
Slide 25
Slide 25 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 25 / 81
x
Por que Design-First?
Slide 26
Slide 26 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 26 / 81
x
Por que Design-First?
Slide 27
Slide 27 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 27 / 81
x
Por que Design-First?
Slide 28
Slide 28 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 28 / 81
x
Por que Design-First?
Slide 29
Slide 29 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 29 / 81
x
Por que Design-First?
Slide 30
Slide 30 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 30 / 81
x
Por que Design-First?
Slide 31
Slide 31 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 31 / 81
Por que Design-First?
openapis.org
Slide 32
Slide 32 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 32 / 81
Por que Design-First?
...
paths
openapis.org
Slide 33
Slide 33 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 33 / 81
Por que Design-First?
...
paths
+
components
openapis.org
Slide 34
Slide 34 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 34 / 81
Por que Design-First?
...
paths
+
components
+
$ref
...
openapis.org
Slide 35
Slide 35 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 35 / 81
Por que Design-First?
Slide 36
Slide 36 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 36 / 81
Por que Design-First?
Zero Code
Slide 37
Slide 37 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 37 / 81
Por que Design-First?
Zero Code Code
Slide 38
Slide 38 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 38 / 81
Por que ReST?
Por que ReST?
Slide 39
Slide 39 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 39 / 81
Por que ReST?
Slide 40
Slide 40 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 40 / 81
+ Client-Server
Por que ReST?
Slide 41
Slide 41 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 41 / 81
+ Client-Server
+ Stateless - não existe persistência de estado
Por que ReST?
Slide 42
Slide 42 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 42 / 81
+ Client-Server
+ Stateless - não existe persistência de estado
+ Cache - Declaração explícita se a resposta é cacheável
Por que ReST?
Slide 43
Slide 43 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 43 / 81
+ Client-Server
+ Stateless - não existe persistência de estado
+ Cache - Declaração explícita se a resposta é cacheável
+ Uniformidade de Interface
Por que ReST?
Slide 44
Slide 44 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 44 / 81
+ Client-Server
+ Stateless - não existe persistência de estado
+ Cache - Declaração explícita se a resposta é cacheável
+ Uniformidade de Interface
+ Camadas - Impossibilidade de determinar “tipo” de conexão
Por que ReST?
Slide 45
Slide 45 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 45 / 81
… e, além disso...
… e, além disso...
Slide 46
Slide 46 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 46 / 81
… e, além disso...
SQL HTTP(S)
C
R
U
D
Slide 47
Slide 47 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 47 / 81
… e, além disso...
SQL HTTP(S)
Create
Retrieve
Update
Delete
Slide 48
Slide 48 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 48 / 81
… e, além disso...
INSERT
SQL HTTP(S)
Create
Retrieve
Update
Delete
Slide 49
Slide 49 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 49 / 81
… e, além disso...
INSERT
SQL HTTP(S)
Create
Retrieve
Update
Delete
POST
Slide 50
Slide 50 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 50 / 81
… e, além disso...
INSERT
SELECT
SQL HTTP(S)
Create
Retrieve
Update
Delete
POST
Slide 51
Slide 51 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 51 / 81
… e, além disso...
INSERT
SELECT
SQL HTTP(S)
Create
Retrieve
Update
Delete
POST
GET
Slide 52
Slide 52 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 52 / 81
… e, além disso...
INSERT
SELECT
UPDATE
SQL HTTP(S)
Create
Retrieve
Update
Delete
POST
GET
Slide 53
Slide 53 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 53 / 81
… e, além disso...
INSERT
SELECT
UPDATE
SQL HTTP(S)
Create
Retrieve
Update
Delete
POST
GET
PATCH / PUT
Slide 54
Slide 54 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 54 / 81
… e, além disso...
INSERT
SELECT
UPDATE
DELETE
SQL HTTP(S)
Create
Retrieve
Update
Delete
POST
GET
PATCH / PUT
Slide 55
Slide 55 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 55 / 81
… e, além disso...
INSERT
SELECT
UPDATE
DELETE
SQL HTTP(S)
Create
Retrieve
Update
Delete
POST
GET
PATCH / PUT
DELETE
Slide 56
Slide 56 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 56 / 81
httpstatuses.com
… e, além disso...
‘bora falar de status HTTP?
Slide 57
Slide 57 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 57 / 81
httpstatuses.com
… e, além disso...
Sim, precisamos falar de status HTTP...
Slide 58
Slide 58 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 58 / 81
httpstatuses.com
Mais
… e, além disso...
Slide 59
Slide 59 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 59 / 81
httpstatuses.com
Mais 201, 204, 401, 403, 404,
405, 406, 413, 429...
… e, além disso...
Slide 60
Slide 60 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 60 / 81
httpstatuses.com
Mais 201, 204, 401, 403, 404,
405, 406, 413, 429...
Menos
… e, além disso...
Slide 61
Slide 61 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 61 / 81
httpstatuses.com
Mais 201, 204, 401, 403, 404,
405, 406, 413, 429...
Menos 200, 400.
… e, além disso...
Slide 62
Slide 62 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 62 / 81
httpstatuses.com
Mais 201, 204, 401, 403, 404,
405, 406, 413, 429...
Menos 200, 400.
Nunca*
… e, além disso...
Slide 63
Slide 63 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 63 / 81
httpstatuses.com
Mais 201, 204, 401, 403, 404,
405, 406, 413, 429...
Menos 200, 400.
Nunca* 5xx.
… e, além disso...
Slide 64
Slide 64 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 64 / 81
Create
Retrieve
Update
Delete
INSERT
SELECT
UPDATE
DELETE
POST
GET
PATCH / PUT
DELETE
SQL HTTP(S) Response
… e, além disso...
Slide 65
Slide 65 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 65 / 81
Create
Retrieve
Update
Delete
INSERT
SELECT
UPDATE
DELETE
POST
GET
PATCH / PUT
DELETE
SQL HTTP(S) Response
201
… e, além disso...
Slide 66
Slide 66 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 66 / 81
Create
Retrieve
Update
Delete
INSERT
SELECT
UPDATE
DELETE
POST
GET
PATCH / PUT
DELETE
SQL HTTP(S) Response
201
200
… e, além disso...
Slide 67
Slide 67 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 67 / 81
Create
Retrieve
Update
Delete
INSERT
SELECT
UPDATE
DELETE
POST
GET
PATCH / PUT
DELETE
SQL HTTP(S) Response
201
200
204
… e, além disso...
Slide 68
Slide 68 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 68 / 81
Create
Retrieve
Update
Delete
INSERT
SELECT
UPDATE
DELETE
POST
GET
PATCH / PUT
DELETE
SQL HTTP(S) Response
201
200
204
204
… e, além disso...
Slide 69
Slide 69 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 69 / 81
FERRAMENTAS!
FERRAMENTAS!
Slide 70
Slide 70 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 70 / 81
●
Documentation
●
Linting
●
Mocking
●
Proxying
●
Testing
FERRAMENTAS!
Slide 71
Slide 71 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 71 / 81
LINTING
spectral - stoplight.io/open-source/spectral
Postman - postman.com
Slide 72
Slide 72 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 72 / 81
MOCKING
prism - stoplight.io/open-source/prism
Postman - postman.com
Slide 73
Slide 73 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 73 / 81
DOCUMENTATION
elements - stoplight.io/open-source/elements
redoc-cli - yarnpkg.com/package/redoc-cli
Postman - postman.com
Slide 74
Slide 74 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 74 / 81
PROXYING
prism - stoplight.io/open-source/prism
Postman - postman.com
Slide 75
Slide 75 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 75 / 81
TESTING
httpie.io
http-prompt - github.com/httpie/http-prompt
Postman - postman.com
usebruno.com
terminaltrove.com/atac
Slide 76
Slide 76 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 76 / 81
http-prompt
x
Slide 77
Slide 77 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 77 / 81
+ http-prompt
Slide 78
Slide 78 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 78 / 81
http-prompt
Performance
Testes Rápidos
Pipeline
Slide 79
Slide 79 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 79 / 81
“Tudo-em-um”
Gerência de grandes APIs
Replayability
Features que são melhores em aplicações GUI
E mais...
Slide 80
Slide 80 text
galvao.eti.br
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 80 / 81
Concluindo...
Slide 81
Slide 81 text
galvao.eti.br
Muito Obrigado!
CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 12/13/24 - 81 / 81
Dúvidas, Críticas, Elogios, etc…? ‘bora conversar!