Question

I have a Restler-powered API (api.example.com) and I have a website for developers (developer.example.com). My aim is to be able to explore the API from the latter site.

But as I add this to the API Explorer options: discoveryUrl:"http://api.example.com/resources.json" it doesn't work (displays "0 : error http://api.example.com/resources.json") even though these facts:

Could you tell me what can be the cause of this issue?

Was it helpful?

Solution

This is because of the browser that is restricting javascript not to load a remote resource without proper permission

Read more about Cross-origin resource sharing from the Wikipedia

In order to enable cross domain access, enable crossOriginResourceSharing on your api server as shown in the following example

use Luracast\Restler\Restler;
use Luracast\Restler\Defaults;

require_once "../../../vendor/restler.php";

Defaults::$crossOriginResourceSharing = true;

$r = new Restler();
$r->addAPIClass('MinMax');
$r->addAPIClass('MinMaxFix');
$r->addAPIClass('Type');
$r->addAPIClass('Resources');
$r->handle();

Above example is live in http://restler3.luracast.com/tests/param/resources.json you may want to try that from your remote explorer

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top