Book Image

Express.js Blueprints

By : Ben Augarten, Marc Kuo, Eric Lin, Aidha Shaikh, Fabiano Pereira Soriani, Geoffrey Tisserand, Chiqing Zhang, Kan Zhang
Book Image

Express.js Blueprints

By: Ben Augarten, Marc Kuo, Eric Lin, Aidha Shaikh, Fabiano Pereira Soriani, Geoffrey Tisserand, Chiqing Zhang, Kan Zhang

Overview of this book

<p>APIs are at the core of every serious web application. Express.js is the most popular framework for building on top of Node.js, an exciting tool that is easy to use and allows you to build APIs and develop your backend in JavaScript. Express.js Blueprints consists of many well-crafted tutorials that will teach you how to build robust APIs using Express.js.</p> <p>The book covers various different types of applications, each with a diverse set of challenges. You will start with the basics such as hosting static content and user authentication and work your way up to creating real-time, multiplayer online games using a combination of HTTP and Socket.IO. Next, you'll learn the principles of SOA in Node.js and see them used to build a pairing as a service. If that's not enough, we'll build a CRUD backend to post links and upvote with Koa.js!</p>
Table of Contents (14 chapters)

Considering user history


Our users will probably want to always be paired to meet new people, so we have to avoid repetitive meetings. How should we handle this?

First, we need to allow for a method to set up new meetings. Think of it as a button in an app that would trigger a request to the route POST/meeting/new.

This endpoint will reply with the status 200 when the request is allowed and a pair is found, or if there is no pair but they are now attached to a meeting object and can now be matched with another user; 412 if the user is already scheduled in another meeting and 400 in case the expected e-mail of the user isn't sent; in this case, it can't be fulfilled because the user wasn't specified.

Note

The usage of status codes is somewhat subjective, (see a more comprehensive list on Wikipedia at http://en.wikipedia.org/wiki/List_of_HTTP_status_codes). However, having distinct responses is important so that the client can display meaningful messages to the user.

Let's implement an Express...