JavaScript Fetch API In 90 Seconds #JavaScriptJanuary

preview_player
Показать описание
Watch the entire #JavaScriptJanuary series from the beginning!

The Fetch API makes it easy to retrieve data from an external source.

The first parameter is the URL that will provide the data. The second parameter is optional and is an object containing options.

By default, without any options, fetch uses the “Get” method. We also use other methods with fetch. That’s where the options come in.

After our URL we include our options object. The first option will be the method, and we will use “Post”. Next we’ll include the data that we want to send in the body. In order to send it properly we have to wrap it in JSON.stringify. And lastly, we include our headers option with our content type set to application / json.

After that we have our first “.then” that receives the response and processes the JSON. And our second “.then” can then do something with the response data.

In this instance we receive the data that we sent along with an id that the server added.

There are other factors to consider when using fetch such as error handling. Note that if you receive an error status such as a 404 error, fetch will still resolve successfully. So you will need to do some extra error handling.

I'll be releasing a new video every day in January! Stay tuned..
_____________________________________

📚 Learn to CODE in just a FEW months here:
_____________________________________

🛠️ Tools I use:

_____________________________________

💖 Show support!
_____________________________________

Watch Next:
_____________________________________

Connect With Me:
_____________________________________

** Affiliate Disclaimer: Some of the above links may be affiliate links, which may generate me a sales commission at no additional cost to you.

#JavaScriptJanuary #31Days31Videos #codeSTACKr
Рекомендации по теме
Комментарии
Автор

Thanks for all of the support! Stay tuned for a new video every day in January!!

Watch the entire #JavaScriptJanuary series from the beginning!

📚 My Favorite Web Design Books 📚
Web Design with HTML, CSS, JavaScript and jQuery Set by Jon Duckett (paid link)

codeSTACKr
Автор

Great Content i am very pleased cheers from israel

RonCoKat
Автор

Thank you Sir, I can't Fetch two url together. Please help me.

mihirdas
Автор

I'm not to sure how to make a javascript fetch URL where you paste it in the bar on a browser then it sends back the cookies credentials

Please help me!

zoel