We have already touched upon the topic of making AJAX requests. There are many ways to make AJAX requests; the two most common approaches are:
- Using the fetch API; the fetch API is a web standard and is thus built into most browsers
- Using the
ajax()
method, nowadays built into the RxJS library; it used to exist in a library called Rx.Dom
The fetch()
API is a web standard. You can find the official documentation at the following link: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API. The fetch()
API is Promise
-based, which means we need to convert it to an Observable
before use. The API exposes a fetch()
method, which takes a mandatory URL parameter as the first argument, with the second argument being an optional object that allows you to control which body to send, if any, which HTTP verb to use, and so on.
We have already mentioned how to best deal with it in the context of RxJS. It is worth repeating though. It is not as simple as just taking our fetch and sticking...