Connector does not support `defaultBody()`?
boryn opened this issue · comments
Either I'm wrong, or I have just discovered, that connectors do not support defaultBody()
?
We came across an API which accepts the key not over the headers, but through the POST body.
So we prepared the request classes with Method::POST
and HasFormBody
and added an array with the API key to defaultBody()
method in the connector, but it seems that the request classes do not take into account that array from the connector.
I believe adding support for defaultBody()
to the connector won't break anything (of course, one needs to remember to use proper method at the request class).
We solved it by a workaround described here: #408
public function boot(PendingRequest $pendingRequest): void
{
$connector = $pendingRequest->getConnector();
$pendingRequest->setBody(new FormBodyRepository($connector->getCredentials()));
}
Hey @boryn
If you add the same trait/interface to the connector as well as your request you will be able to add support for defaultBody()
on your connector. If the body type is "mergable" e.g JSON, then the body will be merged with the request.
Please could you share your use case more please?
@boryn https://docs.saloon.dev/the-basics/request-body-data/xml-body#connector-body Here is an example of a connector using the defaultBody()
Hey @boryn I'm going to close this issue now as it looks like it has been resolved, just say if you need anything.