I have a RESTful API that allows retrieval of data through requests such as GET http://example.com/users/id/1
(Coded following this tutorial).
The code igniter controller looks like this:
class Example_api extends REST_Controller {
function user_get()
{
$data = array('returned: '. $this->get('id'));
$this->response($data);
}
This API was written specifically for the reason that I should be able to access the same code logic from the web frontend as well as mobile apps etc. Now, the mobile app is easy to write but I want to find the strategy for using the API from the web site. The website is essentially sitting on the same server that offers this API and it does not seem right to me to make an HTTP request to the API from code and go through the network again.
So, the question is, how do I use the API from the php code in the same site without going through the network.
example.com
with a reference to a Unix socket, you could avoid the TCP/IP stack altogether. I wonder if it's worth doing, though: unless your application server layer is very low latency, the overhead of going through the network layer locally may be negligible.