Shevek
Shevek

Reputation: 4063

Parent links in HATEOAS

I am new to REST and HATEOAS and trying to create a simple API.

I have a simple one to many parent child relationship.

I have created the api as follows:

Parents: http://example.com/api/parents

Parent: http://example.com/api/parents/123

Children of Parent: http://example.com/api/parents/123/children

Child of Parent: http://example.com/api/parents/123/children/456

I am now adding hypermedia links to all of the responses.

Each response has a self link and the parent responses have a children link.

Should I add a parent link to the child responses?

If the resource was located at http://example.com/api/children/456 then of course it will need the link.

But this is specifically where the link is to a parent in the child's resource address.

i.e. http://example.com/api/parents/123 is a substring of http://example.com/api/parents/123/children/456

Upvotes: 1

Views: 1143

Answers (1)

Torsten
Torsten

Reputation: 752

This sounds like you should use the HAL Rest Standard:

https://apigility.org/documentation/api-primer/halprimer

You have the links to your subresource in in the main resource. And HATEOS supports HAL, you won't have to do by hand

Upvotes: 1

Related Questions