Proxy for web service/api, add destination site url and api key

133 views
Skip to first unread message

Pedro Ruivo

unread,
Jul 29, 2023, 7:49:51 AM7/29/23
to Fusio
I haver five sites using the same software for e-commerce, and their url/domain is different based on function.

I'm evaluating using Fusio to be a gateway to these e-commerce sites API's, these API's use API Token or Oauth (for the moment API key)
The client software to access the API of these e-commerce sites is prepared to use the existing API, but I believe I can just the API calls is necessary.

My doubt it's really about ease of doing the following:

Receive call from the client app and have Fusio proxy that call to the endpoint based on a url passed by the client.
This way I would need to configure only one proxy action/route fand the destination of the proxied call would be determined by the url on the call.

Could I make that in Fusion and how would it be done ?
Thanks,
Nest Regards

Christoph Kappestein

unread,
Jul 29, 2023, 9:07:03 PM7/29/23
to Fusio
Hi Peter,

in general this should be possible, so you could use the HTTP Processor action s. https://docs.fusio-project.org/docs/backend/api/action/http-processor to proxy an HTTP
call to a remote API. I`am currently not 100% sure how you like to call a different endpoint passed by the client, if there is additional logic you can of course always create
i.e. a PHP action to handle this custom logic.

best regards
Christoph

Pedro Ruivo

unread,
Nov 25, 2023, 8:09:51 PM11/25/23
to Fusio
I've been on and off on Fusio but have gotten some time to get back to it now and restarted from scratch with the latest Fusio v4.
Regarding my post about the HTTP Processor it seems in fact that it won't be possible to do it the way i thought.

So the solution would be to build a PHP Sandbox or Processor action.

So here's what I'm trying while using a simple GET api:
The API I'm targeting is working, I'm getting the expected result, while simply using the browser or postman.
The API requires as parameters an API key, which will is variable, and the method I'm using simply lists a table of countries.
So in Fusio what I did was to create an action and it's corresponding operation/route to call this API.

The endpoint that is responding correctly, and that I want to call in Fusio, as the following url:

What i want to call in my App, pointing to Fusio, has action with access, table and action predefined, and I'd like it to look like this:

I'm using PHP Sandbox for the moment as I'm still trying to connect VS to Fusio, so here's my code:

<?php

use Fusio\Action;
use Fusio\Request;
use Fusio\Response;

function execute(Request $request, Response $response)
{
$params = $request->getArguments();

$osclassApiKey = $params["apikey"];
$osClassApiUrl = $params["apiurl"];

// Build my request
$request = Fusio\Request::create($osclassApiKey);
$request->setMethod("GET");
$request->setQuery([
"key" => $osclassApiKey,
"access" => "read",
"table" => "country",
"action" => "listAll",
]);

// Call the endpoint API using Service class
$service = Fusio\Service::get($osclassApiUrl);
$response = $service->call($request);

return $response;
}

This looks something it should work but the problem is I'm getting a 204 status, and an empty response of course.

What should I be doing differently and any suggestion on why I'm getting an empty response  ?

Christoph Kappestein

unread,
Nov 30, 2023, 1:14:54 PM11/30/23
to Fusio
Hi Peter,

if you use the PHP Sandbox action your script needs to return a response s.

since your script does not return a response Fusio returns a 204 Status-Code.

best regards
Christoph

Reply all
Reply to author
Forward
0 new messages