Hi guys, now I’m diving into the deeper parts of JS and it’s getting more challenging. These concepts “Promises, Async and Await, HTTP Request” are they considered the backend of JS?
You will use them a lot when communicating with various APIs and such but they aren’t unique to backend work if that’s what you mean.
The HTTP request concept is foreign to me as I’m learning it through code academy . I wasn’t sure if this is something I should know or how useful it is. So is this part of the frontend language from js? If it is, that’s a lot of new information to soak in.
Yes, one thing you can definitely do with JS is connect to web servers to pull down information. You would most likely use a promise for that, taking advantage of async/await for the convenience they provide. I would recommend you become familiar with how to do this.
These things are absolutely critical for building web applications so, yes, you need to learn them
Maybe it’s just me after learning oop, but it feels overwhelming learning HTTP request syntax, do you remember writing HTTP methods/boilerplate when doing a request? Doesn’t come naturally for me.
I think most people use fetch nowadays instead of XMLHttpRequest (if that’s what you are referring to by HTTP request?).
Correct, it looks like fetch is the latest one from es6???
Promises are just a way to handle asynchronous work in JS. They can be used on the frontend or backend.
async/await
is a different form of a Promise. It’s really a Promise under the covers but is a little “cleaner”. It can be used on the frontend or backend.
And http requests are just a way send or receive data to a server (a backend, somewhere, maybe yours, maybe someone else’s). You can use them on the frontend or backend. They call a backend, but that call can take place from the frontend or a backend. For example, I once wrote a server that would make a request another server. My frontend made and http request to my server that made an http request to another server that returned the data to my server that returned the data to my frontend. That’s a fairly simple setup.
Just making an http request is not “backend”. I assume that at this point you are writing frontend, so that is what this is - you are simply making a request to a backend that someone else wrote. It would be like saying that eating in a 4-star restaurant does not make me a chef - I’m just eating what someone else prepared. (By that analogy I don’t mean to imply that frontend is less important than backend.)
The FCC section “APIs and Microservices” deals with creating your own servers. (I switch them back and forth, but backend deals with - among other things - servers and you will sometimes hear the frontend referred to as a “client”.)
Things like Promises and http requests often go together because http requests are inherently asynchronous and Promises are an elegant way to handle that. (There are also 'async/await`, callbacks, and generator functions). Making http requests are fundamental to most web pages.
As stated, these are all very, very, very important concepts for JS. They are also very confusing when you’re getting into them so don’t get discouraged. You are not imagining it - things are getting hard. Everyone goes through this.
No it’s a browser thing, a replacement for XMLHTTPRequest, which is also a browser thing; not Javascript the language, just an API written in JavaScript.
fetch
is function that returns a Promise (which were standardised as part of ES6, but have been around for a long time). Promises are now the normal way of dealing with async code in JavaScript (and in turn, async/await syntax is built on top of Promises). So Promises are part of JS, async/await is part of JS, and they’re very important. fetch
and other HTTP-related stuff is available on platforms that you program using JavaScript (the browser, primarily) and they are also very important if you want to do anything useful.
Kevin, thanks for taking your time breaking it down. You really nailed it and I went through it with Code Academy, after reading your response, it gave me a clearer sense, and thanks for the encouragement. I’ll stay committed and will get this down!!!
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.