Skip to main content
main-content

Über dieses Buch

This quick guide teaches you how to build scalable APIs using the Node.js platform and ES6 (EcmaScript 2015).

Developing systems for the wide range of devices available in the modern world requires the construction of APIs designed to work only with data in a centralized manner, allowing client-side applications to be developed separately and have a unique interface for the final user.

Node.js has proven itself to be an excellent platform for building REST APIs because of its single-thread architecture. It has a low learning curve and can be understood by anyone who has a basic understanding of the JavaScript language.

Use Building APIs with Node.js today to understand how Node.js APIs work, and how you can build your own.

What You Will Learn

How to build scalable APIs using the Node.js platform

How to use ES6, Express, Passport, ApiDoc, Mocha, Helmet and more

How to integrate an SQL database through Sequelize.js and build a single page application using Vanilla.js

Who This Book Is For

Ideal for developers who have a basic understanding of JavaScript and Node.js.

Inhaltsverzeichnis

Frontmatter

Chapter 1. Introduction to Node.js

Node.js is a low-level, highly scalable platform. It was created explicitly to be an experiment in asynchronous processing. Using Node.js, you will program directly with many network and Internet protocols or use libraries that have access to operating system (OS) resources. To program in Node.js you only need to master JavaScript language; that’s right, only JavaScript! The JavaScript runtime used in this platform is the famous Javascript V8, which is also used in Google Chrome.

Caio Ribeiro Pereira

Chapter 2. Setting Up the Environment

In this chapter, we are going to install Node.js on the most used OSs (Windows, Linux, and MacOSX). However, the entire book uses MacOSX as the default OS. Don’t worry about the differences among these OSs, because all examples in this book are compatible with all the three OS platforms.

Caio Ribeiro Pereira

Chapter 3. Managing Modules with NPM

Just like RubyGems from Ruby or Maven from Java, Node.js also has a package manager, Node Package Manager (NPM). It has become so popular throughout the community that beginning with the 0.6.X Node.js version it was integrated within the main Node.js installer, becoming the standard manager of this platform. This helped the developers at that time, because it made several projects converge to this tool.

Caio Ribeiro Pereira

Chapter 4. Building an API

Now that we have the Node.js environment installed and ready to work, we are going to explore the creation of our REST API application. This kind of application is currently being developed by many projects and companies, because it has the advantage of an application focused only on feeding any client-side application with data. Nowadays, it’s quite common to create web and mobile apps that consume data from one more APIs. This means that several kinds of client applications consult the same server focused on dealing with data. Besides, it also allows each application—client or server—to be worked with by different teams.

Caio Ribeiro Pereira

Chapter 5. Working with SQL Databases

In Chapter 4, we created simple routes for the application to list tasks via a static data model. That was enough to start to explore some basic concepts about API resources.

Caio Ribeiro Pereira

Chapter 6. CRUDify API Resources

In this chapter, we’ll continue to explore the new functions from Sequelize and also organize the API’s routes and some middlewares of Express. The create, read, update, delete (CRUD) will be built using the Tasks and Users models.

Caio Ribeiro Pereira

Chapter 7. Authenticating Users

Our API already has tasks and users resources, which, thanks to the Sequelize framework, are integrated into a SQL database, in our case SQLite3. We have already implemented their routes via the main routing functions provided by Express.

Caio Ribeiro Pereira

Chapter 8. Testing the Application: Part 1

Creating automated tests is highly recommended. There are several types of tests: unitary, functional, acceptance, and others. This chapter focuses only on the acceptance test, which in our case aims to test the outputs and behaviors of our API’s routes.

Caio Ribeiro Pereira

Chapter 9. Testing the Application: Part 2

Continuing the test implementation, now focus next on writing some tests for the resources: tasks and users.

Caio Ribeiro Pereira

Chapter 10. Documenting the API

If you have reached this chapter and your application is working correctly—with routes to the management tasks and users, integrated with a database, and with user authentication via JSON Web Token—congratulations! You have created, following some best practices, a REST API using Node.js. If you intend to use this pilot project as a base to construct your own API, then you already have enough of an application to deploy it into a production environment.

Caio Ribeiro Pereira

Chapter 11. Preparing the Production Environment

Cross-origin resource sharing (CORS) is an important HTTP mechanism. It is responsible for allowing or denying asynchronous requests from other domains.

Caio Ribeiro Pereira

Chapter 12. Building the Client-Side App: Part 1

After building a REST API using Node.js using JavaScript ES6 language, for the final two chapters of this book, we’ll create a new project. This time it will be a front-end project using the best of JavaScript.

Caio Ribeiro Pereira

Chapter 13. Building the Client-Side App: Part 2

Continuing with the client application construction, to this point we have an application with the main layout that connects with the API and allows us to authenticate a user to access the system. In this chapter, we are going to build the main features for users to be able to manage their tasks.

Caio Ribeiro Pereira

Backmatter

Weitere Informationen

Premium Partner

Neuer Inhalt

BranchenIndex Online

Die B2B-Firmensuche für Industrie und Wirtschaft: Kostenfrei in Firmenprofilen nach Lieferanten, Herstellern, Dienstleistern und Händlern recherchieren.

Whitepaper

- ANZEIGE -

Best Practices für die Mitarbeiter-Partizipation in der Produktentwicklung

Unternehmen haben das Innovationspotenzial der eigenen Mitarbeiter auch außerhalb der F&E-Abteilung erkannt. Viele Initiativen zur Partizipation scheitern in der Praxis jedoch häufig. Lesen Sie hier  - basierend auf einer qualitativ-explorativen Expertenstudie - mehr über die wesentlichen Problemfelder der mitarbeiterzentrierten Produktentwicklung und profitieren Sie von konkreten Handlungsempfehlungen aus der Praxis.
Jetzt gratis downloaden!

Bildnachweise