Why do we always use renderRawResponse in the HTTP request lessons?

renderRawResponse(jsonResponse) and replace it with renderResponse(jsonResponse)

Why in the lesson must we always render the raw response and immediatly after replace it with the proper response?
Is this just to show that both options are possible or is it a must? :S I suppose I could play around with it to find out mself but I figure I would use the forums today.

Hey Jonathan! :slight_smile: How are you doing?

I see nobody as answered you yet. Have you find out eventually?

I suppose you’re referring to the lessons about Requests of the JS Course. I think it’s actually a good question and I had it myself when i followed that lessons too.

The answer is in the helperFunctions.js file, generally there are always those two types of functions
renderResponse() and renderRawResponse(). Conceptually they do exactly what their name says, check this one out for example:

If you test them out you see that they work in a similar way, but what is displayed in the html will be different:

  • cleaned data merged into a <p> html element in the first case
  • an object printed as a string in the second one.

So the purpose of rendering the renderRawResponse() is to show us what is the actual response that comes from the request, which clearly needs some refinement in order to be used in our website or web app.

Generally the use of the API is simply this:

  • get some data from somewhere (raw input)
  • take what you need (cleaning/polishing of the raw input)
  • do some elaborations or rendering with it (service)

Hopefully this makes some sense.

Cheers, :slight_smile:

Okay, i see. So it is required to use render it first then delete it and clean it up? Good to know. I thought maybe you could skip that step and it was just to show how it’s done. Thanks!

You can skip it unless there’s a step that specifically checks if you are actually using one instead of the other. That could give you an error unless you use first one and then the other one.

If you’ve got here it means you should be close to the end, yes?