Learn the technologies used in the course Building APIs Using Hapi in Node.js
There are great libraries available, not only for web services, but for database interaction and many other functions. These libraries can be installed using npm, the Node Package Manager. In fact, when I was working at LinkedIn, our API service ran on Ruby on Rails, but wasn't able to keep up with the enormous traffic load. Moving to Node.js solved that problem. Hapi is a library for Node.js which provides web server functionality. You may be familiar with Express, a more commonly known web server library, but Hapi brings a different flavor to this functionality.
Express is designed to be very minimal, and Hapi provides a lot more functionality. Hapi provides plug-in functionality with a rich array of possibilities. To start with, it supports logging, which I appreciate greatly. Server side caching is possible with multiple storage options that can be enabled with a few lines of configuration. Cookies can be parsed and processed. Sessions are supported. One big area of struggle with web servers is file uploading, and this is handled easily using Hapi.
The coding interface is very straightforward and supports a great deal of customization and configuration. For the back end API, we'll be working with Fitbit. I'll go into more detail about this later, but I'm excited to give you a quick introduction to this API as it's one of my favorites. Fitbit is one of the best written and supported APIs I've encountered. It's widely used by hundreds of partners, so it's likely to stay around. The functionality is available without a tracker. Anyone can get an account and use it for health tracking.
While there are several Fitbit node libraries, I chose to go with Fitbit-node. The interface is clean and straightforward, making it easy to integrate Fitbit into your Node application. There is an authentication plug-in for Fitbit available via Hapi, but I wanted to use the same library for interactions and authentication. The library handles token exchange and access and makes it easy to access and process work in the API. It uses Promises as well, which allows for cleaner, more maintainable code. The database I chose to use was MongoDB.
While there are other popular document database frameworks, I like Mongo for several reasons. It's well maintained and supported. Drivers are available for major programming languages, and these drivers are actively maintained. All of the drivers work very similarly, so it's easy to move between different languages while still working with Mongo. Its performant and scalable. It allows for ad hoc queries as well as specific indexing. And finally, the library I chose to interact with Mongo is Mongoose.
Mongoose has a very large install base, so working with it is a great skill to have. It uses standard function names and calls. The Schema-based system ensures that the items within the database are consistent, and in includes built-in type casting, validation, query building, business logic hooks, and more out of the box.
- Setting up the development environment
- Consuming an API using HTTPie
- Inspecting Mongo data
- Updating the server for MongoDB read functionality
- Setting up application endpoints
- Implementing user endpoints, progress endpoints, and promises