REST (REpresentational State Transfer)

Tell us what’s happening:
Describe your issue in detail here.
Hello everybody, I’m stack on the solution of the REST challenge. I don’t really understand the syntax and I don’t know where do I have to write the code. Untill now, I’ve been writing all the code in the same file, myApp.js.
any help
Hopefully I’ll finish the course with a bit of help.

Your project link(s)

solution: https://replit.com/@footroot72/boilerplate-express

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36

Challenge: Serve JSON on a Specific Route

Link to the challenge:

You are missing the callback handler function in your get.

Example from the docs (just a syntax example).

app.get('/', function (req, res) {
  res.send('GET request to homepage')
})

:sob: :sob: :sob: :face_with_symbols_over_mouth: :face_with_symbols_over_mouth:
I don’t want to cry… can anyone show me the solution, please?
:weary:

It would be helpful if you explained your confusion and asked questions.

I know your code is passing but you are using app.use(). It is a GET request so you want to use app.get(). You have in effect created a middleware function which isn’t what the challenge is asking for.

Replace use with get and remove the call to next()

Thank you very much for the help.
I know I should be asking questions, probably because i’m so beginner I still don’t know what to ask.

I write all the code on the file myApp.js, this file has got other pieces of code of the previous challenges.
Is that correct?
What do i espect to see?
On this one I know I have to see the message “Hello json” but I dont know where.

this is my solution

app.get("/json", function(req, res) {
res.json(
{ “Message”: “Hello json” });
});
I didn’t know how to run it so I just put /json at the end and it work but when I put it on the solution it doesn’t work.
https://boilerplate-express.footroot72.repl.co/json

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.