Hi, i've used the platform api before and loved it. The 2.4 release had some nice new features.
A feature I'm still missing is getting resources from a different REST API which I would need to make a gateway REST API.
Ideally I'd love to write a resource in the gateway rest API like the code example below to reference a different rest API, but I'd like to do it the proper way.
/**
* @ProxyApiResource(url="https://demo.api-platform.com/docs.jsonld", remoteResource="Book")
*/
class Book {
public $title;
public $isbn;
}
Or maybe with environment variable support for some flexibility?
/**
* @ProxyApiResource(url="%env(APP_DEMO_API_URL)%", remoteResource="Book")
*/
class Book {
public $title;
public $isbn;
}
So my question is: what is the proper way to start such a task? Maybe it's nice to have as a core feature.
Why don't you create a custom Data Provider? Configuring via annotation will enforce to decorate a metadata factory, so I suggest to implement some interface:
interface ProxiedResource {
public function getTarget(): string
}
class Book implements ProxiedResource {
public function getTarget(): string
{
return 'http://...';
}
}
and check against ProxiedResource implementation within RestrictedDataSource. Piece of cake.
Use a custom DataProvider and DataPersister.
thanks. I think I have enough ideas to write a library.
Most helpful comment
Use a custom DataProvider and DataPersister.