UseMuffin/Webservice

Embedded resources in api result

Closed this issue · 1 comments

blieb commented

Hi,

I'm trying to understand if it is possible to get add related resources to response.

I do a request to the API to get messages, the response contains an array of the user that it posted id. simple example:

{
	"id": "36f23f2bc90d35f0",
	"created": "2020-06-24T09:27:40.217+00:00",
	"body": "This is a message",
	"user": {
		"id": 1,
		"name": "jan",
		"email": "test@test.com"
	}
}

is it possible some way that the user array transforms to a User resource inside the Message Resource? At the moment when I do $this->_transformResults($query->endpoint(), $messages); it will returns a MessageResource with an array instead of user resource.

ADmad commented

Currently there's no support for associations so there's no way for the MessagesEndpoint to know that user array should be converted into User resource. You'll have to handle the conversion yourself, for e.g. in the Message resource class' constructor.