Can anyone help me understand why do we request the API with FARADAY why not use AJAX ?? If we using Faraday what is the advantage over Ajax ?
I'm new to rails apologize if it is a basic question.
Can anyone help me understand why do we request the API with FARADAY why not use AJAX ?? If we using Faraday what is the advantage over Ajax ?
I'm new to rails apologize if it is a basic question.
Faraday is an HTTP client to do requests server to server.
Ajax is a technology to do asyncronous requests from the client to the server.
They are different things with different purposes.
The are not even comparable.
Faraday is a gem for performing HTTP requests from the server (to another server). Much like the Net::HTTP module from the standard library.
AJAX is used in the browser (client) to send HTTP requests asyncronously (without reloading the page).
Both can be used to fetch data from anywhere on the internet but run in completely different contexts. Which is more suited depends completly on the problem at hand.
The server is not limited by the same domain origin policy and other browser security features but doing requests on the server or proxying via the server ties up server resources and delays sending the response back.
The browser can perform a high number of asyncronous requests and do them after the inital page load which means AJAX can provide a more responsive user experience.