O'Reilly logo

Learning Node.js for Mobile Application Development by Milorad Jevdjenic, Stefan Buttigieg

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

Implementing our GET handlers

Let's begin by implementing basic GET methods for our resources. You may recall that we mentioned before that a good REST API should at least implement two of them—GET by ID and GET all. Since we like to be standards-compliant, that is what we will use here.

Implementing a router

Our first order of business is to provide a way for our Node.js instance to differentiate between the different URLs that it receives requests for. Until now, our server only had to handle requests to its root URL (http://localhost:8080/), but in order to do something more interesting, we want to be able to generate custom responses for more specific URLs, such as http://localhost:8080/api/products.

Fortunately, Node.js again provides an out-of-the-box ...

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

Start Free Trial

No credit card required