With a REST API I can receive a response in XML or in JSON. This can be done using PHP or Javascript (using jQuery) for example.
I want to know the advantages and the disadvantages of the different languages. This is what I figured out so far:
The Javascript call will not place a load on your server if the REST API is on an external domain (i.e. not yours). jQuery's ajax() call offers a work-around to allow you to GET data from external domains.
Use PHP if:
Use Javascript when:
Disregarding any other server side language, when you create your own REST API, the most common way is using PHP for backend and JavaScript for the client side. But there is also the possibility to write JavaScript at the backend (Learning Server-Side JavaScript with Node.js).
Javascripts run on the client side and does not make a load on the server when fetching data with external URLs.
Thats only half the truth, if I understood your question right. If you need data from an external source, JavaScript will be prevented from doing so due to the same origin policy. But there are many possibilities to load data from some other origin like ajax proxy (using your backend as bridge) or JSONP.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With