Slide 1

Slide 1 text

www.galvao.eti.br CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 1 / 58 APIs com PHP Todas as imagens usadas neste material são de propriedade de suas entidades v. 0.1.0 APIs com da Criação ao Consumo

Slide 2

Slide 2 text

Programador Sênior na Vox Tecnologia Primeiro Postman Supernova do Brasil Presidente da ABRAPHP – Associação Brasileira de Profissionais PHP Diretor da ConFLOSS e da PHP Conference Brasil Evangelista e Contribuidor para a Linguagem Evangelista Laminas Project Embaixador Fedora LATAM Professor Convidado (Especialista) de Pós-Graduação (PR e SC) 25+ anos desenvolvendo sistemas com interface web 20+ destes com PHP ≃ 15 com Zend Framework / Laminas Project Palestrante em eventos nacionais e internacionais Professor de cursos presenciais e a distância Quem?! CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 2 / 58 www.galvao.eti.br www.galvao.eti.br

Slide 3

Slide 3 text

Objetivo CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 3 / 58 www.galvao.eti.br Falar sobre APIs, particularmente APIs Web e demonstrar a criação e consumo de uma API simples utilizando a linguagem PHP. APIs com PHP

Slide 4

Slide 4 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 4 / 58 www.galvao.eti.br APIs fazem sentido APIs com PHP

Slide 5

Slide 5 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 5 / 58 www.galvao.eti.br APIs fazem sentido APIs com PHP strlen( $str ) int

Slide 6

Slide 6 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 6 / 58 www.galvao.eti.br APIs fazem sentido APIs com PHP strlen( $str ) int ponto de acesso

Slide 7

Slide 7 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 7 / 58 www.galvao.eti.br APIs fazem sentido APIs com PHP strlen( $str ) int ponto de acesso informação

Slide 8

Slide 8 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 8 / 58 www.galvao.eti.br APIs fazem sentido APIs com PHP strlen( $str ) int ponto de acesso informação resultado

Slide 9

Slide 9 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 9 / 58 www.galvao.eti.br APIs fazem sentido APIs com PHP strlen( $str ) https://foo/ produto / 253 int string (JSON, etc...) ponto de acesso informação resultado

Slide 10

Slide 10 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 10 / 58 www.galvao.eti.br APIs fazem sentido APIs com PHP strlen( $str ) https://foo/ produto / 253 int string (JSON, etc...) ponto de acesso informação resultado

Slide 11

Slide 11 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 11 / 58 www.galvao.eti.br APIs fazem sentido APIs com PHP strlen( $str ) https://foo/ produto / 253 int string (JSON, etc...) ponto de acesso informação resultado

Slide 12

Slide 12 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 12 / 58 www.galvao.eti.br APIs fazem sentido APIs com PHP strlen( $str ) https://foo/ produto / 253 int string (JSON, etc...) ponto de acesso informação resultado

Slide 13

Slide 13 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 13 / 58 www.galvao.eti.br Web faz sentido APIs com PHP

Slide 14

Slide 14 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 14 / 58 www.galvao.eti.br Web faz sentido APIs com PHP simples

Slide 15

Slide 15 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 15 / 58 www.galvao.eti.br Web faz sentido APIs com PHP simples implementada

Slide 16

Slide 16 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 16 / 58 www.galvao.eti.br Web faz sentido APIs com PHP simples implementada suportada

Slide 17

Slide 17 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 17 / 58 www.galvao.eti.br php faz sentido APIs com PHP

Slide 18

Slide 18 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 18 / 58 www.galvao.eti.br php faz sentido APIs com PHP simples

Slide 19

Slide 19 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 19 / 58 www.galvao.eti.br php faz sentido APIs com PHP simples livre

Slide 20

Slide 20 text

Por quê? CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 20 / 58 www.galvao.eti.br php faz sentido APIs com PHP simples livre robusta

Slide 21

Slide 21 text

CRIAÇÃO

Slide 22

Slide 22 text

Conceito CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 22 / 58 www.galvao.eti.br APIs com PHP

Slide 23

Slide 23 text

Conceito CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 23 / 58 www.galvao.eti.br APIs com PHP PSRs 7 (HTTP Messages) 15 (HTTP Server Request Handlers) www.php-fig.org

Slide 24

Slide 24 text

Conceito CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 24 / 58 www.galvao.eti.br APIs com PHP PSRs 7 (HTTP Messages) 15 (HTTP Server Request Handlers) 13, 17, 18… HAL Factories Client www.php-fig.org

Slide 25

Slide 25 text

Prática CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 25 / 58 www.galvao.eti.br APIs com PHP

Slide 26

Slide 26 text

Prática CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 26 / 58 www.galvao.eti.br APIs com PHP

Slide 27

Slide 27 text

Prática CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 27 / 58 www.galvao.eti.br APIs com PHP

Slide 28

Slide 28 text

Prática CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 28 / 58 www.galvao.eti.br APIs com PHP

Slide 29

Slide 29 text

Prática CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 29 / 58 www.galvao.eti.br APIs com PHP

Slide 30

Slide 30 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 30 / 58 www.galvao.eti.br Use código-fonte que você não entende completamente e prepare-se para ser julgado DISCLAIMER APIs com PHP

Slide 31

Slide 31 text

CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 31 / 58 www.galvao.eti.br Use código-fonte que você não entende completamente e prepare-se para ser julgado pelo Rei Koala do Inferno. DISCLAIMER APIs com PHP

Slide 32

Slide 32 text

Prática CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 32 / 58 www.galvao.eti.br APIs com PHP composer create-project \ mezzio/mezzio-skeleton \ /var/www/html/APIs_e_PHP github.com/galvao/APIs_e_PHP

Slide 33

Slide 33 text

Roteamento CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 33 / 58 www.galvao.eti.br APIs com PHP config/routes.php

Slide 34

Slide 34 text

Configuração CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 34 / 58 www.galvao.eti.br APIs com PHP config/pipeline.php

Slide 35

Slide 35 text

Configuração CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 35 / 58 www.galvao.eti.br APIs com PHP config/autoload/database.global.php

Slide 36

Slide 36 text

Configuração CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 36 / 58 www.galvao.eti.br APIs com PHP config/autoload/dependencies.global.php

Slide 37

Slide 37 text

Configuração CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 37 / 58 www.galvao.eti.br APIs com PHP src/App/ConfigProvider.php

Slide 38

Slide 38 text

Factory CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 38 / 58 www.galvao.eti.br APIs com PHP src/App/Handler/ProdutoHandlerFactory.php

Slide 39

Slide 39 text

Handler (Pre) CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 39 / 58 www.galvao.eti.br APIs com PHP src/App/Handler/ProdutoHandler.php

Slide 40

Slide 40 text

Handle GET CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 40 / 58 www.galvao.eti.br APIs com PHP src/App/Handler/ProdutoHandler.php

Slide 41

Slide 41 text

Handle POST CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 41 / 58 www.galvao.eti.br APIs com PHP src/App/Handler/ProdutoHandler.php

Slide 42

Slide 42 text

Handle PATCH CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 42 / 58 www.galvao.eti.br APIs com PHP src/App/Handler/ProdutoHandler.php

Slide 43

Slide 43 text

Handle DELETE CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 43 / 58 www.galvao.eti.br APIs com PHP src/App/Handler/ProdutoHandler.php

Slide 44

Slide 44 text

CONSUMO

Slide 45

Slide 45 text

Prática CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 45 / 58 www.galvao.eti.br APIs com PHP

Slide 46

Slide 46 text

Prática CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 46 / 58 www.galvao.eti.br APIs com PHP Guzzle

Slide 47

Slide 47 text

Prática CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 47 / 58 www.galvao.eti.br APIs com PHP Guzzle composer require guzzlehttp/guzzle github.com/galvao/APIs_e_PHP-consumidor

Slide 48

Slide 48 text

Setup CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 48 / 58 www.galvao.eti.br APIs com PHP consumir.php Guzzle

Slide 49

Slide 49 text

GET CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 49 / 58 www.galvao.eti.br APIs com PHP consumir.php GET Guzzle

Slide 50

Slide 50 text

POST CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 50 / 58 www.galvao.eti.br APIs com PHP consumir.php POST Guzzle

Slide 51

Slide 51 text

PATCH CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 51 / 58 www.galvao.eti.br APIs com PHP consumir.php PATCH Guzzle

Slide 52

Slide 52 text

DELETE CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 52 / 58 www.galvao.eti.br APIs com PHP consumir.php DELETE Guzzle

Slide 53

Slide 53 text

Conclusão CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 53 / 58 www.galvao.eti.br APIs com PHP

Slide 54

Slide 54 text

Conclusão CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 54 / 58 www.galvao.eti.br APIs com PHP APIs Web

Slide 55

Slide 55 text

Conclusão CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 55 / 58 www.galvao.eti.br APIs com PHP APIs Web com PHP

Slide 56

Slide 56 text

Conclusão CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 56 / 58 www.galvao.eti.br APIs com PHP APIs Web com PHP com PSRs

Slide 57

Slide 57 text

Conclusão CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 57 / 58 www.galvao.eti.br APIs com PHP APIs Web com PHP com PSRs com Framework*

Slide 58

Slide 58 text

Muito obrigado! CC Attribution-ShareAlike 3.0 Unported License by Er Galvão Abbott - 5/20/22 - 58 / 58 www.galvao.eti.br Dúvidas? Críticas? Elogios?! ? APIs com PHP