Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Conversation

@Bedi06
Copy link

@Bedi06 Bedi06 commented Jul 18, 2023

Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in HOW_TO_MARK.md in the root of this repository

Your Details

  • Your Name:
  • Your City:
  • Your Slack Name:

Homework Details

  • Module:
  • Week:

Notes

  • What did you find easy?

  • What did you find hard?

  • What do you still not understand?

  • Any other notes?

Copy link

@ShayanMahnam ShayanMahnam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job Bedi!

  • Try to look at this Link to see whats the diffrence between .send and .json
  • I will now add some error handling for you, which will be useful in the future.

}


app.get("/echo",function(request,response){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app.get("/echo", (req, res) => {
  const wordQuery = req.query.word;
  if (!wordQuery) {
    return res.status(400).json({ error: "Query parameter 'word' is missing." });
  }

  try {
    res.send(`You entered: ${wordQuery}`);
  } catch (error) {
    res.status(500).json({ error: "Internal Server Error" });
  }
});

response.send(getRandomQuote);
});

app.get("/quotes/search",function(request,response){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app.get("/quotes/search", (req, res) => {
  const term = req.query.term;
  if (!term) {
    return res.status(400).json({ error: "Search term is missing in the query parameter." });
  }

  try {
    const quotesFound = quotesMatching(term);
    res.json(quotesFound);
  } catch (error) {
    res.status(500).json({ error: "Internal Server Error" });
  }
});

response.send(quotes);
});

app.get("/quotes/random",function(request,response){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app.get("/quotes/random", (req, res) => {
  try {
    const randomQuote = lodash.sample(quotes);
    res.json(randomQuote);
  } catch (error) {
    res.status(500).json({ error: "Internal Server Error" });
  }
});

});

//START OF YOUR CODE...
app.get("/quotes",function (request,response){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

app.get("/quotes", (req, res) => {
  try {
    res.json(quotes);
  } catch (error) {
    res.status(500).json({ error: "Internal Server Error" });
  }
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants