CRIANDO API`S
EMPRESARIAIS
COM
@fidelissauro
Matheus Fidelis
Developer / DevOps
Superlógica Tecnologias
Twitter: @fidelissauro
Github: /msfidelis
Blog: nanoshots.com.be
2
“Any application that can be
written in Javascript, will
eventually be written in
Javascript”
Jeff Atwood - co-fundador
da StackOverflow
3
● Criado por Eran Hammer
● Sr. Architect of Mobile
Platform
● Responsável pela arquitetura
das maiores aplicações Mobile
no Walmart
● OAuth e OAuth2
4
● Express não foi suficiente para o Walmart
● Falhou em grandes equipes e grandes projetos.
● Queria uma solução corporativa.
5
OPEN SOURCE
https://github.com/walmartlabs
● Criado para grandes equipes
● Sistemas complexos
● Ideal para alta disponibilidade
● Segurança
● Proteção de Memória
● Proteção do Event Loop
● Gerenciamento de Timeouts
● Validações Integradas
● Tratamento de Requests
abortados, lifecycle, limites de
clientes e etc
7
8
REN & STIMPY
COMPARAÇÕE
S
9
10
SERVER
11
ROUTES
12
ROUTES
13
BENCHMARKS
https://raygun.com/blog/node-performance/
14
SO QUE ASSIM...
15
NA VIDA REAL...
▫ Hapi ▫ Express
▫ Body-parser
▫ Cookie-parser
▫ Consign
▫ Muster
▫ … middlewares
16
17
NA VIDA REAL...
▫ Express é uma abstração do HTTP Kernel do
Node.
▫ Express te provê ROTAS. Apenas.
▫ Hapi faz vários tratamentos, debug, fallbacks
▫ Proteção do Lifecycle do request
▫ Proteção da memória
▫ Todo o acompanhamento e parsing do HTTP
18
NO GERAL...
▫ Para aplicações grandes
▫ Apps com muitos devs
▫ Apps com muitas
validações e segurança
▫ Coisas Simples
▫ Interfaces REST
▫ POC’s e Services
▫ Cloud Functions
19
DOCKER
PLUGINS
https://hapijs.com/plugin
s
20
▫ Isso sobre m#rd@
▫ Exceptions Logging
▫ Legal pra registrar Dumps
▫ Logs limpos para rastreio
21
https://github.com/hapijs/poop
▫ Validação
▫ Validação agressiva dos requests
▫ Resource Responsibility
22
https://github.com/hapijs/joi
23
https://github.com/hapijs/joi
▫ HTTP-friendly
▫ Error Response Codes
24
https://github.com/hapijs/boom
25
https://github.com/hapijs/boom
26
https://github.com/hapijs/boom
▫ 4xx
▫ Boom.badRequest() - 400
▫ Boom.unauthorized() - 401
▫ Boom.forbidden() - 403
▫ Boom.notFound - 404
▫ 5xx
▫ Boom.notFound() - 500
▫ Boom.notImplemented - 501
▫ Boom.serverUnavailable() - 503
▫ Console web para debug
▫ Vários servidores Hapi
▫ Logs dos Requests
▫ Logs limpos para rastreio
27
https://github.com/hapijs/tv
28
▫ Gerenciador de Templates
▫ EJS
▫ Jade
▫ Mustache
▫ Nunjucks
29
https://github.com/hapijs/vision
VISION
▫ PROXY HANDLER
▫ Proxy e Gateway
▫ Altamente customizável
30
https://github.com/hapijs/h2o2
H2O2
31
https://github.com/hapijs/h2o2
H2O2
32
https://github.com/ryanfitz/hapi-auth-jwt
https://github.com/dwyl/hapi-auth-jwt2
JWT/JWT2
33
JWT/JWT2
34
Authentication
▫ HTTP Basic authentication
▫ https://github.com/hapijs/hapi-auth-basic
▫ Bearer token based authentication
▫ https://github.com/johnbrett/hapi-auth-bearer-
token
▫ Firebase
▫ https://github.com/dsdenes/hapi-auth-firebase
35
Messaging
▫ Hapi-rabbit - RabbitMQ
▫ https://github.com/aduis/hapi-rabbit
▫ Hapi-plugin-websocket
▫ https://github.com/rse/hapi-plugin-websocket
▫ Susie
▫ https://github.com/mtharrison/susie
36
Routes
▫ acquaint
▫ https://github.com/genediazjr/acquaint
▫ hapi-routes
▫ https://github.com/bsiddiqui/hapi-router
▫ hapi-auto-route
▫ https://github.com/sitrakay/hapi-auto-route
37
https://hapijs.com/communit
y
38
Hapi e Eu
39
Boreal Server
https://github.com/msfidelis/boreal
40
Boreal Server
https://github.com/msfidelis/boreal
https://hub.docker.com/r/msfidelis/boreal
▫ “RESTfica” qualquer banco MySQL
▫ MySQL, MariaDB, Aurora Servers
▫ Caching, Query Builder com HTTP methods, Process
Management.
▫ Deploy do banco de dados como um Microservice
▫ Feito para rodar com Docker!
41
Pocket Gateway
https://github.com/msfidelis/pocket-
gateway
▫ Micro API Gateway.
42
Perguntas?
▫ https://twitter.com/fidelissauro
▫ https://github.com/msfidelis
▫ http://nanoshots.com.br
▫ msfidelis01@gmail.com
43
https://github.com/msfidelis/hapijs-demo
44
DEMO/DOJO

Criando API's com HapiJS