News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Gonzalo Ayuso:
Building a simple API proxy server with PHP
August 14, 2012 @ 11:07:56

In some of his work with Backbone.js recently, Gonzalo Ayuso has been frustrated by something that's a wall for many developers wanting to work with outside datasources - the browser restriction that prevents cross-domain requests. His solution? Create a REST proxy to live on his server and pass the requests through.

Nowadays there is a header to allow it: Access-Control-Allow-Origin. The problem is that the remote server must set up this header. For example I was playing with github's API and github doesn't have this header. If the server is my server, is pretty straightforward to put this header but obviously I'm not the sysadmin of github, so I cannot do it. What the solution? One possible solution is, for example, create a proxy server at localhost with PHP.

He shares the full code for his project - basically a handler that takes the incoming request and mirrors to out to the public, remote API - request method and all. It uses some of the packages from Symfony (like the http-foundation) and wraps around cURL to handle the requests. The project is available for Composer users as well.

0 comments voice your opinion now!
api proxy server tutorial rest curl wrapper


blog comments powered by Disqus

Similar Posts

Mfana Ronald Conco's Blog: RabbitMQ and PHP Part 2 - Durable Queues and Persistent Messages

php|architect: Stored Procedure Programming for MySQL5 (Part 1)

Zend Developer Zone: Leveraging Zend Framework Components from Adobe Flash Platform Applications

3 Engineers Blog: 3 Step Layouts in Zend Framework

PHP-GTK Community Site: Accessing geo-nick with Zend Framework (Zend_XmlRpc_Client)


Community Events





Don't see your event here?
Let us know!


code community unittest developer podcast framework wordpress threedevsandamaybe testing opinion release laravel install interview list introduction language refactor configure series

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework