O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

RESTful Web API Design with Node.js 10 - Third Edition

Book Description

Design and implement scalable and maintainable RESTful solutions with Node.js 10

About This Book
  • Create rich and scalable RESTful API solutions from scratch
  • Explore the new features of Node.js 10, Express 4.0, and MongoDB
  • Integrate MongoDB in your Node.js application to store and secure your data
Who This Book Is For

If you are a web developer keen to enrich your development skills to create server-side RESTful applications based on the Node.js platform, this book is for you. Some knowledge of REST would be an added advantage, but is definitely not a necessity.

What You Will Learn
  • Install, develop, and test your own Node.js user modules
  • Understand the differences between HTTP and RESTful applications
  • Use self-descriptive URLs and set accurate HTTP status codes
  • Eliminate third-party dependencies in your tests with mocking
  • Implement automation tests for a REST-enabled endpoint with Mocha
  • Secure your services with NoSQL database integration within Node.js applications
  • Integrate a simple frontend using JavaScript libraries available on a CDN server
In Detail

When building RESTful services, it is really important to choose the right framework. Node.js, with its asynchronous, event-driven architecture, is exactly the right choice for building RESTful APIs.

This third edition of RESTful Web API Design with Node.js 10 will teach you to create scalable and rich RESTful applications based on the Node.js platform. You will be introduced to the latest NPM package handler and understand how to use it to customize your RESTful development process. You will begin by understanding the key principle that makes an HTTP application a RESTful-enabled application. After writing a simple HTTP request handler, you will create and test Node.js modules using automated tests and mock objects; explore using the NoSQL database, MongoDB, to store data; and get to grips with using self-descriptive URLs. You'll learn to set accurate HTTP status codes along with understanding how to keep your applications backward-compatible. Also, while implementing a full-fledged RESTful service, you will use Swagger to document the API and implement automation tests for a REST-enabled endpoint with Mocha. Lastly, you will explore some authentication techniques to secure your application.

Style and approach

Step-by-step practical guide to building RESTful applications

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. RESTful Web API Design with Node.js 10 Third Edition
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the author
    2. About the reviewers
    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. REST – What You Did Not Know
    1. REST fundamentals
      1. Principle 1 – Everything is a resource
      2. Principle 2 – Each resource is identifiable by a unique identifier
      3. Principle 3 – Manipulate resources via standard HTTP methods
      4. Principle 4 – Resources can have multiple representations
      5. Principle 5 – Communicate with resources in a stateless manner
    2. The REST goals
      1. Separation of the representation and the resource
      2. Visibility
      3. Reliability
      4. Scalability and performance
    3. Working with WADL
    4. Documenting RESTful APIs with Swagger
      1. Taking advantage of the existing infrastructure
    5. Summary
  7. Getting Started with Node.js
    1. Installing Node.js
      1. Npm
    2. Installing the Express framework and other modules
    3. Setting up a development environment
    4. Handling HTTP requests
    5. Modularizing code
    6. Testing Node.js
      1. Working with mock objects
    7. Deploying an application
      1. Nodejitsu
      2. Microsoft Azure
      3. Heroku
    8. Self-test questions
    9. Summary
  8. Building a Typical Web API
    1. Specifying the API
    2. Implementing routes
    3. Querying the API using test data
    4. Content negotiation
    5. API versioning
    6. Self-test questions
    7. Summary
  9. Using NoSQL Databases
    1. MongoDB – a document store database
    2. Database modeling with Mongoose
    3. Testing a Mongoose model with Mocha
    4. Creating a user-defined model around a Mongoose model
    5. Wiring up a NoSQL database module to Express
    6. Self-test questions
    7. Summary
  10. Restful API Design Guidelines
    1. Endpoint URLs and HTTP status codes best practices
    2. Extensibility and versioning
    3. Linked data
    4. Summary
  11. Implementing a Full Fledged RESTful Service
    1. Working with arbitrary data
    2. Linking
    3. Implementing paging and filtering
    4. Caching
      1. Supplying the Cache-Control header in Express applications
    5. Discovering and exploring RESTful services
    6. Summary
  12. Preparing a RESTful API for Production
    1. Documenting RESTful APIs
    2. Testing RESTful APIs with Mocha
    3. The microservices revolution
    4. Summary
  13. Consuming a RESTful API
    1. Consuming RESTful services with jQuery
    2. Troubleshooting and identifying problems on the wire
    3. Cross Origin Resource Sharing
    4. Content Delivery Networks
    5. Handling HTTP status codes on the client side
    6. Summary
  14. Securing the Application
    1. Authentication
      1. Basic authentication
      2. Passport
        1. Passport's basic authentication strategy
        2. Passport's OAuth Strategy
        3. Passport's third-party authentication strategies
    2. Authorization
    3. Transport layer security
      1. Self-test questions
    4. Summary
  15. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think