Beginning API Development with Node.js

Book description

Learn everything you need to get up and running with cutting-edge API development using JavaScript and Node.js; ideal for data-intensive real-time applications that run across multiple platforms.

Key Features

  • Build web APIs from start to finish using JavaScript across the development stack
  • Explore advanced concepts such as authentication with JWT, and running tests against your APIs
  • Implement over 20 practical activities and exercises across 9 topics to reinforce your learning

Book Description

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.

What you will learn

  • Understand how Node.js works, its trends, and where it is being used now
  • Learn about application modularization and built-in Node.js modules
  • Use the npm third-party module registry to extend your application
  • Gain an understanding of asynchronous programming with Node.js
  • Develop scalable and high-performing APIs using hapi.js and Knex.js
  • Write unit tests for your APIs to ensure reliability and maintainability

Who this book is for

This book is ideal for developers who already understand JavaScript and are looking for a quick no-frills introduction to API development with Node.js. Though prior experience with other server-side technologies such as Python, PHP, ASP.NET, Ruby will help, it's not essential to have a background in backend development before getting started.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Beginning API Development with Node.js
  3. Packt Upsell
    1. Why Subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the Author
    2. About the Reviewer
    3. Packt Is Searching for Authors like You
  5. Preface
    1. Who This Book Is For
    2. What This Book Covers
    3. To Get the Most out of This Book
      1. Download the Example Code Files
      2. Conventions Used
    4. Get in Touch
      1. Reviews
  6. Introduction to Node.js
    1. The Basics of Node.js
      1. Applications of Node.js
      2. Activity: Running Basic Node.js Code
    2. The Module System
      1. Application Modularization
      2. Module Categories
        1. Built-In Modules
        2. npm – Third-Party Module Registry
        3. Scanning for node_modules
        4. Handy npm Commands
        5. Local Modules
      3. Activity: Using a Third-Party Package for the Previous math.js Code
    3. Asynchronous Programming with Node.js
      1. Callbacks
      2. Promises
      3. Async/Await
      4. Activity: Transforming a Text File Using an Async Function
    4. Summary
  7. Building the API - Part 1
    1. Building a Basic HTTP Server
    2. Setting up Hapi.js
      1. Exercise 1: Building a Basic Hapi.js Server
      2. Using an API Client
      3. Returning JSON Strings
      4. Exercise 2: Returning JSON
      5. Using nodemon for Development Workflow
      6. Exercise 3: Using nodemon
      7. Setting up the Logger
      8. Exercise 4: Setting up the Logger
    3. Understanding Requests
      1. A Look at HTTP Request Methods
      2. Exercise 5: Getting a List of Resources
      3. Exercise 6: Getting a Specific Resource
      4. Exercise 7: Creating a New Todo with POST
      5. Exercise 8: Updating a Resource with PUT
      6. Exercise 9: Updating with PATCH
      7. Exercise 10: Deleting a Resource with DELETE
      8. Request Validation
      9. Exercise 11: Validating a Request
    4. Summary
  8. Building the API - Part 2
    1. Working with the DB Using Knex.js
      1. Exercise 12: Setting up the Database
      2. Exercise 13: Connecting to the Database
      3. Exercise 14: Creating a Record
      4. Exercise 15: Reading from the Database
      5. Exercise 16: Updating a Record
      6. Exercise 17: Deleting a Record
      7. Exercise 18: Cleaning up the Code
    2. Authenticating Your API with JWT
      1. Exercise 19: Securing All the Routes
      2. Exercise 20: Adding User Authentication
      3. Authentication versus Authorization
      4. Exercise 21: Implementing Authorization
    3. Testing Your API with Lab
      1. Exercise 22: Writing Basic Tests with Lab
    4. Summary
  9. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Beginning API Development with Node.js
  • Author(s): Anthony Nandaa
  • Release date: July 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789539660