We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Can Phalcon access remote webservices

I want/need Phalcon to be able to get remote data from a webservice and bring it back to the Phalcon server for display. It also needs to supply header parameters as well as path and query parameters.


So the scenario would be like this:

  • Operator would access https://myPhalconSite.com/users/24
  • Phalcon code would then go to https://1.2.3.4 with path params of 'users' and '24' plus header params of 'token' => 'myToken' and 'Accept' => 'application/json' and get a json string in return
  • Phalcon would parse that string and pass it off to the correct view
  • The correct view would display the data of user #24 to the Operator

Forgive the formatting but the markup seems way off.

Can Phalcon do this? What Model class do I use? Is there any example showing something like this? I have googled but no joy. Also I am presuming that Phalcon can indeed unmarshal the json string straight to a given class, or is this an incorrect assumption?

Thanks, Kevin

There's something in the Phalcon Incubator that seems what you're looking for: https://github.com/phalcon/incubator/tree/master/Library/Phalcon/Http/Client



629

So basically - nothing in prime-time yet?



98.9k

If you read the docs the Incubator is proposed functionality for Phalcon, if you include this via Composer it will work as if it's part of the Phalcon functionality already and if it does get included in future your code should still work without the need to use the Incubator.