FAQ: Requests II - Review Requests II

This community-built FAQ covers the “Review Requests II” exercise from the lesson “Requests II”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Review Requests II

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hello Everyone!

In the review of this lesson (https://www.codecademy.com/courses/introduction-to-javascript/lessons/requests-ii/exercises/review-requests-ii?action=resume_content_item) there is a statement:

" await is a keyword that is used to tell a program to continue moving through the message queue while a promise resolves."

In this lesson (https://www.codecademy.com/courses/introduction-to-javascript/lessons/async-await/exercises/await-operator?action=resume_content_item) there is a statement:

" await halts, or pauses, the execution of our async function until a given promise is resolved"

Sounds opposite in my opinion. Could you explain please where my misunderstanding is?

3 Likes

The final lessons of intro to JS talk about Promise, async…await, fetch, and AJAX. I am curious about the difference between them.

For example, is AJAX a framework that we can implement using promises, async…await, or fetch?

Or are the four simply different ways to create asynchronous server-client operations? If so, how do we know when to use which?

3 Likes

I interpreted this as await halts/pauses the current async request, and continues moving through the message queue until the promise is resolved, then the async request continues.

So, rather than waiting for the request to finish before doing anything else, it puts a hold on the action that may take some time to complete, continues with the rest of the queue, then resumes the held action when the promise is ready. Hope this helps.

4 Likes

Excellent question. You made me review the lessons.

This wikipedia article summarizes well what we have learned: https://en.wikipedia.org/wiki/Ajax_(programming)

Hello’
i have a several questions about requests:

  1. when we use the POST it requires an object somtimes its {cache: no-cache} or JSON.stringify({id:200}) and somtimes its simply doesnt exist. what is this Object and what is it used for?
  2. why the object above is not required and why in ‘POST’ we need to add mehtod body’ headers?
  3. what is shortened Url is for? every time i tried in the exercise to see any results when i put diffrent URL’s in the inbox i dont see anything changed, i swear i did everthing by the orders.

Hi there!

I am newbie as well but I will try to explain what I have undertood so far about requests:

A request is the action you wish to carry out in a server, the most important actions are expressed by HTTP verbs :
‘GET’ => when you want to receive data from a server
‘POST’ => when you want to send data into a server
‘PUT’ => when you want to update data in a server
‘DELETE’ => when you want to delete data
(There are at least five more according to MDN Web Docs => ‘HEAD’, ‘CONNECT’, ‘OPTIONS’, ‘TRACE’ and ‘PATH’).

The method fetch has two arguments, the first one is the url of the server and it is compulsatory. If a second argument is not specified, the values by default are => method: ‘GET’ , headers: ’ ’ and body: ’ '.

Depending on the type of HTTP verb and the requirements of the server, you will have to change the values by default of the second argument.

For instance, if you want to retrieve data but the server requires you to identify, the property “headers” must be changed and place your API key. In datamuse they did not require us to identify, so no headers needed.

If you want to send data you have to specify method: ‘POST’, because the default value is ‘GET’. And obviously, you have to send this data, whis is attached to the property body. But before being attached, it should be tranformed from a JavaScript object into a JSON string, and this is done by using the method JSON.stringify(). This is the format the HTTP protocol demands for the body.

In the case of shortened URL the data we send (attached to body) it is the url we want to be shortened. Copy any link and paste it into input. Then click submit and your shortened url should be displayed in text-area.

Hope this helps!

I believe the halting refers to the carrying out the function where async is used. So, while this function is halted the rest of the program doesn’t have to wait for it to resolve, but rather, runs in parallel. I’m not sure what the message que is though, can anyone clarify that part?