Skip to content
Advertisement

Symfony2 – How to perform an external Request

Using Symfony2, I need to access an external API based on HTTPS.

How can I call an external URI and manage the response to “play” with it. For example, to render a success or a failure message?

I am thinking in something like (note that performRequest is a completely invented method):

JavaScript

I have been reading about Buzz and other clients. But I guess that Symfony2 should be able to do it by its own.

Advertisement

Answer

I’d suggest using CURL:

JavaScript

Note: The php on your web server must have the php5-curl library installed.

Assuming the API request is returning JSON data, this page may be useful.

This doesn’t use any code that is specific to Symfony2. There may well be a bundle that can simplify this process for you, but if there is I don’t know about it.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement