0%

Book Description

Developing a hapi Edge shows you how to build enterprise-quality web applications using the hapi service and application framework. By walking through the creation of a real web application, hapi-plugins.com, you will learn how to configure and start hapi, build out APIs, perform authentication, validation, caching, and so much more. You will also discover tips and tricks used in production hapi deployments regarding plugins, testing, debugging, and security. hapi was developed and is used within Walmart and has been battle tested during the most critical days of the year for e-commerce websites, Black Friday. It has proven itself to not only handle extremely high production loads at a breeze but is also a pleasure to work with. The aim of the framework was to address pitfalls in the other established out there, and it has done so without fail.

Book Description

Developing a hapi Edge shows you how to build enterprise-quality web applications using the hapi service and application framework. By walking through the creation of a real web application, hapi-plugins.com, you will learn how to configure and start hapi, build out APIs, perform authentication, validation, caching, and so much more. You will also discover tips and tricks used in production hapi deployments regarding plugins, testing, debugging, and security. hapi was developed and is used within Walmart and has been battle tested during the most critical days of the year for e-commerce websites, Black Friday. It has proven itself to not only handle extremely high production loads at a breeze but is also a pleasure to work with. The aim of the framework was to address pitfalls in the other established out there, and it has done so without fail.

Table of Contents

  1. Preface
    1. Why use hapi?
    2. What should you know prior to reading this book?
    3. Source code/sample app
    4. What will this book teach you?
    5. Authors
  2. 1. Introduction to hapi
    1. History
    2. Book overview
    3. hapi-plugins.com
    4. Style
    5. Summary
  3. 2. Server
    1. Setting up a simple server
    2. Setting up the server for hapi-plugins.com
    3. Glue
    4. Rejoice
    5. Confidence
    6. Server methods
    7. Decorating the server
    8. Configuring for caching
    9. Request lifecycle
    10. Extension points
    11. Summary
  4. 3. Routes
    1. Path processing
    2. Parts of the route
      1. method
      2. vhost
      3. handler
      4. config
      5. path
    3. Server router config options
    4. Summary
  5. 4. The handler
    1. The request
      1. parameters
      2. query
      3. payload
      4. headers
    2. The reply
    3. Organizing handlers
    4. Built-in handlers
      1. File
      2. proxy
    5. Adding common methods to the handler
      1. Binding to server
      2. Decorating the reply
    6. Tails
    7. Defining the handler using server.handler
    8. Liking a plugin example
    9. Uploading files
    10. Summary
  6. 5. Validation
    1. Types of validations
    2. Joi validation
      1. Validation for hapi-plugins.com
    3. Generic data validation with joi
    4. Using a validation function
    5. Summary
  7. 6. Plugins
    1. Creating your own plugin
      1. Plugin configuration
      2. A word on labels and selecting plugins
    2. When to use a plugin
    3. The hapi plugin ecosystem: some common plugins
      1. hapi-auth-basic
      2. blipp
      3. bell
      4. good
      5. tv
      6. lout / hapi-swagger
      7. poop
      8. More plugins
    4. Summary
  8. 7. Authentication
    1. Chapter Overview
    2. Scheme vs strategy
    3. hapi-auth-basic
    4. hapi-auth-cookie
    5. bell
    6. Summary
  9. 8. Models
    1. Using HTTP
      1. Desired Usage
      2. NPM Packages
      3. NPM Downloads
    2. Using a database
      1. Setting up the database
      2. Connecting to the database
      3. Schema Design
    3. Summary
  10. 9. Templating
    1. Configuration
      1. Options
    2. View Loading
    3. Layouts
      1. Configuration
      2. Usage
      3. Exclusion
    4. Partials
      1. Configuration
    5. Helpers
      1. Configuration
      2. Helper Files
      3. Shared Contexts
    6. Summary
  11. 10. Testing
    1. Chapter Overview
    2. History of lab
    3. Installing lab
      1. Installing code
    4. Writing a simple test
    5. Principles of lab
      1. Always asynchronous
      2. Test scripts
      3. Safe globals
      4. Experiments
    6. Writing a hapi test
    7. Code coverage
    8. Reporters
    9. Linting
    10. Plugin Testing
    11. Summary
  12. 11. Debugging
    1. Chapter Overview
    2. console.log
    3. debug mode
    4. TV
    5. Good
    6. REPL
    7. Heap Snapshots
    8. Core Files
    9. Summary
  13. 12. Security
    1. Best practices
      1. Password hashing: BCrypt
      2. XSS
      3. CSRF
      4. SSL
      5. Header stripping
      6. contentSecurityPolicy
      7. CORS
      8. crossdomain.xml
    2. Summary
    3. Review
  14. 13. Appendix
    1. Models
      1. History
      2. Overview of HTTP Clients
      3. Overview of database clients
      4. Connection
      5. Postgres::Sequelize
    2. Schemas
      1. MongoDB::mongodb
      2. MongoDB::Mongoose
      3. Cassandra::Apollo
    3. Templating Engines
      1. Overview of Selected Templating Engines
3.133.141.6