Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

RESTful Web API Design with Node.js - Second Edition
RESTful Web API Design with Node.js - Second Edition
RESTful Web API Design with Node.js - Second Edition
Ebook265 pages2 hours

RESTful Web API Design with Node.js - Second Edition

Rating: 1 out of 5 stars

1/5

()

Read preview

About this ebook

About This Book
  • Create a fully featured RESTful API solution from scratch.
  • Learn how to leverage Node.JS, Express, MongoDB and NoSQL datastores to give an extra edge to your REST API design.
  • Use this practical guide to integrate MongoDB in your Node.js application.
Who This Book Is For

The ideal target audience for this book is web developers who have some experience with RESTful services. Familiarity with basic JavaScript programming techniques is required. No prior experience with Node.js or Express.js is required.

LanguageEnglish
Release dateMay 26, 2016
ISBN9781786463203
RESTful Web API Design with Node.js - Second Edition

Related to RESTful Web API Design with Node.js - Second Edition

Related ebooks

Internet & Web For You

View More

Related articles

Reviews for RESTful Web API Design with Node.js - Second Edition

Rating: 1 out of 5 stars
1/5

1 rating0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    RESTful Web API Design with Node.js - Second Edition - Valentin Bojinov

    Table of Contents

    RESTful Web API Design with Node.js - Second Edition

    Credits

    About the Author

    About the Reviewer

    www.PacktPub.com

    eBooks, discount offers, and more

    Why subscribe?

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Downloading the example code

    Errata

    Piracy

    Questions

    1. REST – What You Did Not Know

    REST fundamentals

    Principle 1 - everything is a resource

    Principle 2 - each resource is identifiable by a unique identifier

    Principle 3 - use the standard HTTP methods

    Principle 4 - resources can have multiple representations

    Principle 5 - communicate statelessly

    The REST goals

    Separation of the representation and the resource

    Visibility

    Reliability

    Scalability and performance

    Working with WADL

    Taking advantage of the existing infrastructure

    Summary

    2. Getting Started with Node.js

    Installing Node.js

    Node Package Manager

    Installing the Express framework and other modules

    Setting up a development environment

    Handling HTTP requests

    Modularizing code

    Testing Node.js

    Working with mock objects

    Deploying an application

    Microsoft Azure

    Nodejitsu

    Self-test questions

    Summary

    3. Building a Typical Web API

    Specifying the API

    Implementing routes

    Querying the API

    Content negotiation

    Cross-origin resource sharing

    API versioning

    Self-test questions

    Summary

    4. Using NoSQL Databases

    Key/value store - LevelDB

    Document store - MongoDB

    Database modeling with Mongoose

    Testing a Mongoose model with Mocha

    Creating a user-defined model around a Mongoose model

    Wiring up a NoSQL database module to Express

    Content delivery network

    Self-test questions

    Summary

    5. Implementing a Fully-Fledged RESTful Service

    Extensibility and versioning

    Working with arbitrary data

    Linking

    Implementing paging and filtering

    Caching

    Supplying the Cache-Control header in Express applications

    Discovering and exploring RESTful services

    Self-test questions

    Summary

    6. Keeping the Bad Guys Out

    Authentication

    Basic authentication

    Passport

    Passport's basic authentication strategy

    Passport's third-party authentication strategies

    Authorization

    Transport Layer Security

    Self-test questions

    Summary

    RESTful Web API Design with Node.js - Second Edition


    RESTful Web API Design with Node.js - Second Edition

    Copyright © 2016 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: March 2015

    Second edition: May 2016

    Production reference: 1200516

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B32PB, UK.

    ISBN 978-1-78646-913-7

    www.packtpub.com

    Credits

    About the Author

    Valentin Bojinov studied computer programming at the Technological School of Electronic Systems in Sofia, Bulgaria, a college within the Technical University of Sofia. He was introduced to programming there and realized that his career would be in research and development. He holds a BSc in telecommunication and information engineering. Then, his interest in data transmission grew, and he ventured into B2B (business-to-business) communication. He is currently pursuing his MSc in software development. Valentin is an expert in Java, SOAP, RESTful web services, and B2B integration.

    A few years after he started his career as a .NET developer, he realized that B2B and SOA were his passion. He then moved to SAP, where he contributed to the development of the web services stack of the SAP JEE platform. He currently works as a senior Java developer for the Bulgarian branch of Seeburger AG, a leader in the B2B and MFT solutions market. There, he develops and maintains several B2B communication adapters, including web services and SAP adapters.

    I would like to take the opportunity to thank my soulmate Galya for putting up with me and with my decision to work on this title. Also, many thanks to my lovely parents, my dad Emil for encouraging me to study computers 20 years ago, and to mummy Anka for always being there for me! Special thanks to all my mentors from TUES for showing me how to learn efficiently and to never give up, the credit here goes mainly to Lubomir Chorbadjiev. I also have to mention my extraordinary colleagues I had the chance to study with! Guys, thanks for always being such good friends and experts! I know I haven’t recently shown on our regular monthly gathering, so next time beer is on me!

    About the Reviewer

    Huseyin BABAL is an enthusiast full stack developer since 2007 who mainly develops web applications by using Java, Node.js and PHP on the backend; AngularJS and Twitter Bootstrap on the frontend; and Elasticsearch and MongoDB for some research projects. He is the author of Node.js in Action on Udemy with 1500+ students. He is also interested in DevOps engineering and applies continuous delivery principles to his projects. He writes tutorials about full stack development on Tuts+ and Java Code Geeks and shares his experiences at public conferences.

    Besides the computer world, he lives in Istanbul with his wonderful wife and two cockatiels. He likes to spend his spare time with his wife by walking at least 1 hour per day, visiting different places, watching cartoons, and going on summer holidays.

    www.PacktPub.com

    eBooks, discount offers, and more

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    https://www2.packtpub.com/books/subscription/packtlib

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

    Why subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print, and bookmark content

    On demand and accessible via a web browser

    Preface

    RESTful services have become the de facto standard data feed providers for social services, news feeds, and mobile devices. They deliver a large amount of data to millions of users; therefore, they need to address high-availability requirements such as reliability and scalability. This book will show you how to utilize the Node.js platform to implement a robust and performant data service. By the end of the book you will have learned how to implement a real-life RESTful service, taking advantage of the modern NoSQL database for serving both JSON and binary content. Important topics such as correct URI structuring and security features are also covered with detailed examples, showing you everything you need to know to start implementing robust RESTful APIs serving content for your applications!

    What this book covers

    Chapter 1, REST – What You Did Not Know, gives you a brief introduction into the history of REST and how it couples with the HTTP protocol.

    Chapter 2, Getting Started with Node.js, teaches you how to install Node.js and how to work with its package manager to install modules, develop your first HTTP server application, and write automated unit tests for the HTTP handler by using mock request objects.

    Chapter 3, Building a Typical Web API, teaches you how to structure your application using human-readable URL and URI parameters and develop a read-only RESTful service application using the filesystem as storage.

    Chapter 4, Using NoSQL Databases, explains how to use LevelDB and MongoDB NoSQL databases, understand the difference between key/value and document data stores, and write automated tests for NoSQL user defined modules.

    Chapter 5, Implementing a Full-Fledged RESTful Service, implements a production-ready RESTful service that uses NoSQL to store its data. You will also learn how to handle binary data and how to version an API while it evolves.

    Chapter 6, Keeping the Bad Guys Out, explains how to restrict access to your data by choosing an appropriate authentication approach, protect data leakage with transport layer security.

    What you need for this book

    The following software is required to test the code present in this book:

    Node.js

    Enide developer studio or the Nodeclipse plugin for the Eclipse IDE

    SoapUI

    OpenSSL

    Who this book is for

    This book targets developers who want to enrich their development skills by learning how to develop scalable, server-side, RESTful applications based on the Node.js platform. You also need to be aware of HTTP communication concepts and should have a working knowledge of the JavaScript language. Knowledge of REST would be an added advantage but is definitely not a necessity.

    Conventions

    In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

    Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user

    Enjoying the preview?
    Page 1 of 1