Full Stack Web Dev (2020)| Send Data to the Back Using The Fetch API (Junior Dev)
The Javascript Fetch API is a cleaner and simpler way of sending HTTP network requests to the backend. It handles GET and POST just like the XHR object, but with less syntax.
No need to open(), make sure headers are set, and make sure to send(). A lot of Fetch is automated for you. You have to handle the response though. There's no way around that. Luckily, the Fetch API uses Javascript Promises.
Also, be careful of status codes. Just because Fetch provides simpler syntax, doesn't mean you get too comfortable. Make sure to check the response status codes--200's, 404's, 500's--before proceeding with your Promise chain.
Promises: lbry://@an_object_is_a#7/javascript_promises#f
2020-01-24
0.0 LBC
None
96520528 Bytes