Creating the REST API

The server of EveryPlantSelectionApp is responsible for retrieving the plant names (the plant families, genuses, and species) and making them available to our client-side code via a simple REST API. To do this, we can use the express Node.js library, which enables us to route HTTP requests to specific functions, easily delivering JSON to our client.

Here's the skeletal beginnings of our server implementation:

import express from 'express';const app = express();const port = process.env.PORT || 3000;app.get('/plants/:query', (req, res) => {  req.params.query; // => The query  res.json({    fakeData: 'We can later place some real data here...'  });});app.listen(  port,  () => console.log(`App listening on port ${port}!`));

As ...

Get Clean Code in JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.