Hey everyone! I’m trying to figure out if it’s possible to use react-admin with my RESTful server that follows HATEOAS principles. Has anyone done this before?
I’m running into some issues because react-admin seems to work mainly with IDs, not full objects. This is especially tricky with the getManyReference
function, where it only gives a field name and ID instead of the whole resource.
I’ve looked at some implementations like HAL and GraphQL, but they kinda go against HATEOAS by grabbing IDs from ‘self’ links. That doesn’t feel right to me.
We’re thinking about tweaking how we use the target
parameter. Instead of a field name, we might use it to name the referencing resource. This way, the data provider could fetch the full record with all its links. Then we’d use the resource
field to pick the right link.
Has anyone tried something similar or have any other ideas? I’d love to hear your thoughts!
Implementing HATEOAS with react-admin is indeed challenging, but not impossible. One approach you might consider is creating a middleware layer between react-admin and your HATEOAS API. This layer could handle the translation of react-admin’s ID-based requests into appropriate HATEOAS calls, and vice versa for responses.
For the getManyReference
function specifically, you could implement logic in your data provider to fetch the full resource based on the provided field name and ID, then extract the necessary information from the HATEOAS response. This maintains the HATEOAS principles while still working within react-admin’s framework.
Additionally, exploring custom hooks or components to handle HATEOAS navigation within your react-admin interface could provide a more seamless integration. It requires some additional development, but it allows you to leverage both technologies effectively.
hey Lu_57Read, i’ve actually been tinkering with something similar! have u considered using a custom data provider? u could intercept the react-admin requests and translate them to HATEOAS-friendly calls. it’s a bit of work, but might solve ur problem without compromising on HATEOAS principles. just a thought!
ooh, interesting problem! have you tried using a custom hook to fetch full resources via hateoas links? it might simplify react-admin integration and maintain hateoas benefits. wondering if this approach aligns with what you need?