Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript REST APIs with Express Managing Data and Asynchronous Code Refactor the Get One Quote Route

Frank Kynard
Frank Kynard
6,958 Points

Why is my local host 3000/quotes/8271 showing all of my records instead of just the one with the id

 app.get('/quotes/:id', async (req, res) => {
  const quote = await records.getQuotes(req.params.id);
  res.json(quote);
});
Frank Kynard
Frank Kynard
6,958 Points

full code

const express = require('express');
const app = express();

const records = require('./records');

// Send a GET request to /quotes to READ a list of quotes
app.get('/quotes', async (req, res) => {
  const quotes = await records.getQuotes();
  res.json(quotes);
});
// Send a GET request to /quotes/:id to READ(view) a quote
app.get('/quotes/:id', async (req, res) => {
  const quote = await records.getQuotes(req.params.id);
  res.json(quote);
});
// Send a POST request to /quotes to Create a new quote
// Send a PUT request to /quotes/:id to UPDATE (edit) a quote
// Send a DELETE request to /quotes/:id to DELETE a quote
// Send a GET request to /quotes/quote/random to READ (view) a random quote

app.listen(3000, () => console.log('Quote API listening on port 3000!'));

1 Answer

Frank Kynard
Frank Kynard
6,958 Points

Never mind I figured out the problem. It should be getQuote not getQuotes