SlideShare ist ein Scribd-Unternehmen logo
1 von 16
An introduction to hapi.js
Dave Stevens
@davestevens84 | davestevens84@gmail.com
What is hapi.js?
• Framework for building web applications and
services
• Eran Hammer
• Walmart
• Robust, Stable, Reliable
• Security is a key consideration
BENEFITS
What’s so great about hapi
Modularization
• Allows for logical modularization of your
application
• Rich plugin interface
• Large application can be easily distributed
over multiple smaller modules
Tested at scale
• All Walmart Black Friday traffic 2 years
running
• Didn’t explode
• APIs and web applications at Yahoo, Disney,
Paypal and Zappos
Eco-system
• Good (process monitoring and logging)
• Good-replay (replay log events!)
• Glue (compose servers from manifests)
• TV (Interactive debug console)
• Joi (Schema validation)
• Etc… https://github.com/hapijs
Installing
• npm install --save hapi
Creating a server
var Hapi = require(‘hapi’);
var server = new Hapi.Server();
server.connection({
host:’localhost’,
port: 9009
});
Creating a server (2)
server.route({
path: ‘/’,
method: ‘GET’,
handler: function (request, reply) {
reply(‘Hi VegasJS!’);
}
});
server.start();
Routing
server.route({
path: ‘/’,
method: ‘GET’,
handler: function (request, reply) {
reply(‘Hi VegasJS!’);
}
});
Values surrounded by {} populate request.params in handler
e.g. path:‘/name/{firstname}’ would mean that /name/dave results
in request.params.firstname being equal to ‘dave’
Very configurable to handle multitude of eventualities – one example,
multi-segment parameters:
path: ‘/name/{names*}’ then requesting /name/dave/andrew/stevens
would result in request.params.names being ‘dave/andrew/stevens’
which we can split on ‘/’ to create array, etc.
Routing
server.route({
path: ‘/’,
method: ‘GET’,
handler: function (request, reply) {
reply(‘Hi VegasJS!’);
}
});
Specify HTTP method here, can also have multiple methods in
An array eg.
method: [‘PUT’, ‘POST’],
Routing
server.route({
path: ‘/’,
method: ‘GET’,
handler: function (request, reply) {
reply(‘Hi VegasJS!’);
}
});
Plugins
• Allow you to build out your application
components as self-contained modules
• Also manipulate requests and other events,
hook in to server events, etc.
• Kinda like middleware but think bigger!
Decorate
• Avoid duplicate code by using
server.decorate
server.decorate(‘reply’, ‘error’, function (err) {
console.error(err);
return this.response({message: ‘There was an
error’}).code(500);
});
// in handler, reply.error(err);
Next Steps
• > npm install –g makemehapi
• > makemehapi
• Challenges and guided learning!
• Talk to me
• #hapijs on Twitter (official: @hapijs)
• #hapi on Freenode IRC
• http://bit.ly/orghapi
Obligatory “Look, I Finished” Slide
• Twitter @davestevens84
• Email davestevens84@gmail.com
• Accost me in the street

Weitere ähnliche Inhalte

Was ist angesagt?

PowerShell for SharePoint Admins
PowerShell for SharePoint AdminsPowerShell for SharePoint Admins
PowerShell for SharePoint Admins
Rick Taylor
 

Was ist angesagt? (19)

Introduction to Chef
Introduction to ChefIntroduction to Chef
Introduction to Chef
 
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIWordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
 
WordPress and The Command Line
WordPress and The Command LineWordPress and The Command Line
WordPress and The Command Line
 
2016 W3C Conference #9 : 컨테이너와 웹 어플리케이션
2016 W3C Conference #9 : 컨테이너와 웹 어플리케이션2016 W3C Conference #9 : 컨테이너와 웹 어플리케이션
2016 W3C Conference #9 : 컨테이너와 웹 어플리케이션
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello Production
 
005. a React project structure
005. a React project structure005. a React project structure
005. a React project structure
 
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
 
Ansible Introduction
Ansible IntroductionAnsible Introduction
Ansible Introduction
 
Express JS
Express JSExpress JS
Express JS
 
Integration and Acceptance Testing
Integration and Acceptance TestingIntegration and Acceptance Testing
Integration and Acceptance Testing
 
PowerShell for SharePoint Admins
PowerShell for SharePoint AdminsPowerShell for SharePoint Admins
PowerShell for SharePoint Admins
 
PowerShell for SharePoint Developers
PowerShell for SharePoint DevelopersPowerShell for SharePoint Developers
PowerShell for SharePoint Developers
 
Putting the 'ctions' in Azure Fun-ctions
Putting the 'ctions' in Azure Fun-ctionsPutting the 'ctions' in Azure Fun-ctions
Putting the 'ctions' in Azure Fun-ctions
 
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloudphp[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
 
Writing your First Ansible Playbook
Writing your First Ansible PlaybookWriting your First Ansible Playbook
Writing your First Ansible Playbook
 
What's New in v2 - AnsibleFest London 2015
What's New in v2 - AnsibleFest London 2015What's New in v2 - AnsibleFest London 2015
What's New in v2 - AnsibleFest London 2015
 
SSR with Quasar Framework - JSNation 2019
SSR with Quasar Framework - JSNation 2019SSR with Quasar Framework - JSNation 2019
SSR with Quasar Framework - JSNation 2019
 
Drupal VM for Drupal 8 Dev - MidCamp 2017
Drupal VM for Drupal 8 Dev - MidCamp 2017Drupal VM for Drupal 8 Dev - MidCamp 2017
Drupal VM for Drupal 8 Dev - MidCamp 2017
 
Chef at WebMD
Chef at WebMDChef at WebMD
Chef at WebMD
 

Ähnlich wie An Introduction to hapi.js

Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
Tom Croucher
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
Mohammad Qureshi
 

Ähnlich wie An Introduction to hapi.js (20)

Nodejs first class
Nodejs first classNodejs first class
Nodejs first class
 
Nodejs web,db,hosting
Nodejs web,db,hostingNodejs web,db,hosting
Nodejs web,db,hosting
 
NodeJS
NodeJSNodeJS
NodeJS
 
EWD 3 Training Course Part 5b: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5b: First Steps in Building a QEWD ApplicationEWD 3 Training Course Part 5b: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5b: First Steps in Building a QEWD Application
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Node.js to the rescue
Node.js to the rescueNode.js to the rescue
Node.js to the rescue
 
APIs, now and in the future
APIs, now and in the futureAPIs, now and in the future
APIs, now and in the future
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to Chef
 
Intro to node and mongodb 1
Intro to node and mongodb   1Intro to node and mongodb   1
Intro to node and mongodb 1
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web Applications
 
Java Web Programming on Google Cloud Platform [1/3] : Google App Engine
Java Web Programming on Google Cloud Platform [1/3] : Google App EngineJava Web Programming on Google Cloud Platform [1/3] : Google App Engine
Java Web Programming on Google Cloud Platform [1/3] : Google App Engine
 
EWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5a: First Steps in Building a QEWD ApplicationEWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
EWD 3 Training Course Part 5a: First Steps in Building a QEWD Application
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Node.js vs Play Framework
Node.js vs Play FrameworkNode.js vs Play Framework
Node.js vs Play Framework
 
Java Servlets.pdf
Java Servlets.pdfJava Servlets.pdf
Java Servlets.pdf
 
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
EWD 3 Training Course Part 36: Accessing REST and Web Services from a QEWD ap...
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Android networking-2
Android networking-2Android networking-2
Android networking-2
 
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
 

Kürzlich hochgeladen

VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
nilamkumrai
 
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Chandigarh Call girls 9053900678 Call girls in Chandigarh
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
imonikaupta
 

Kürzlich hochgeladen (20)

(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Al Barsha Night Partner +0567686026 Call Girls Dubai
Al Barsha Night Partner +0567686026 Call Girls  DubaiAl Barsha Night Partner +0567686026 Call Girls  Dubai
Al Barsha Night Partner +0567686026 Call Girls Dubai
 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
 
Dubai Call Girls Milky O525547819 Call Girls Dubai Soft Dating
Dubai Call Girls Milky O525547819 Call Girls Dubai Soft DatingDubai Call Girls Milky O525547819 Call Girls Dubai Soft Dating
Dubai Call Girls Milky O525547819 Call Girls Dubai Soft Dating
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 

An Introduction to hapi.js

  • 1. An introduction to hapi.js Dave Stevens @davestevens84 | davestevens84@gmail.com
  • 2. What is hapi.js? • Framework for building web applications and services • Eran Hammer • Walmart • Robust, Stable, Reliable • Security is a key consideration
  • 4. Modularization • Allows for logical modularization of your application • Rich plugin interface • Large application can be easily distributed over multiple smaller modules
  • 5. Tested at scale • All Walmart Black Friday traffic 2 years running • Didn’t explode • APIs and web applications at Yahoo, Disney, Paypal and Zappos
  • 6. Eco-system • Good (process monitoring and logging) • Good-replay (replay log events!) • Glue (compose servers from manifests) • TV (Interactive debug console) • Joi (Schema validation) • Etc… https://github.com/hapijs
  • 8. Creating a server var Hapi = require(‘hapi’); var server = new Hapi.Server(); server.connection({ host:’localhost’, port: 9009 });
  • 9. Creating a server (2) server.route({ path: ‘/’, method: ‘GET’, handler: function (request, reply) { reply(‘Hi VegasJS!’); } }); server.start();
  • 10. Routing server.route({ path: ‘/’, method: ‘GET’, handler: function (request, reply) { reply(‘Hi VegasJS!’); } }); Values surrounded by {} populate request.params in handler e.g. path:‘/name/{firstname}’ would mean that /name/dave results in request.params.firstname being equal to ‘dave’ Very configurable to handle multitude of eventualities – one example, multi-segment parameters: path: ‘/name/{names*}’ then requesting /name/dave/andrew/stevens would result in request.params.names being ‘dave/andrew/stevens’ which we can split on ‘/’ to create array, etc.
  • 11. Routing server.route({ path: ‘/’, method: ‘GET’, handler: function (request, reply) { reply(‘Hi VegasJS!’); } }); Specify HTTP method here, can also have multiple methods in An array eg. method: [‘PUT’, ‘POST’],
  • 12. Routing server.route({ path: ‘/’, method: ‘GET’, handler: function (request, reply) { reply(‘Hi VegasJS!’); } });
  • 13. Plugins • Allow you to build out your application components as self-contained modules • Also manipulate requests and other events, hook in to server events, etc. • Kinda like middleware but think bigger!
  • 14. Decorate • Avoid duplicate code by using server.decorate server.decorate(‘reply’, ‘error’, function (err) { console.error(err); return this.response({message: ‘There was an error’}).code(500); }); // in handler, reply.error(err);
  • 15. Next Steps • > npm install –g makemehapi • > makemehapi • Challenges and guided learning! • Talk to me • #hapijs on Twitter (official: @hapijs) • #hapi on Freenode IRC • http://bit.ly/orghapi
  • 16. Obligatory “Look, I Finished” Slide • Twitter @davestevens84 • Email davestevens84@gmail.com • Accost me in the street