Book Image

Beginning API Development with Node.js

By : Anthony Nandaa
3.5 (2)
Book Image

Beginning API Development with Node.js

3.5 (2)
By: Anthony Nandaa

Overview of this book

Using the same framework to build both server and client-side applications saves you time and money. This book teaches you how you can use JavaScript and Node.js to build highly scalable APIs that work well with lightweight cross-platform client applications. It begins with the basics of Node.js in the context of backend development, and quickly leads you through the creation of an example client that pairs up with a fully authenticated API implementation. By the end of the book, you’ll have the skills and exposure required to get hands-on with your own API development project.
Table of Contents (9 chapters)

Testing Your API with Lab


In this section, we will have a brief look at writing unit tests for Hapi.js APIs. Testing is a huge topic that perhaps requires a whole course on its own, but in this section, we will be introducing the essential parts to get you up and running.

Let's first underscore the importance of writing unit tests for your API:

  • Maintainability: This is what I consider as the most important value of adding tests to your software. When you have tests, you can be confident to come back months later and, modify your code without worrying whether you broke anything by your update.
  • Requirement specifications: Tests make sure that your code meets the requirements. For our example, we started off by implementing the requirements since we wanted to pass across some basic concepts. But in practice, it is way better to start off with the tests before implementing your routes.
  • Automated testing: You realized that in our previous examples, we kept checking our API client (Insomnia) to see...