I am working on a REST-based API and have some problems figuring out what the parent / child relationships will represent. (I write beans in CXF and use JAX-RS and JAXB. I started with the basic example provided by CXF)
My problem is that you have Foo and Bar. There is a 1-N relationship with Foo and Bar, meaning 1 Foo has many bars. My question is, what is the canonical way to find out what Bars a Foo is? And what is the canonical way to access Bar resources owned by Foo?
I realized that, for example, I can list Foos at:
GET http: // xxx / fooservice / foos
And work with one foo at:
PUT / UPDATE / DELETE http: // xxx / fooservice / foo / {fooid}
But how do I list the bars that Foo 121 has? And how do I access them? I noticed that apparently the JAXB marshaller by default does not only display the Collections attributes for the bean, so if Foo:
Foo
- String id
- String name
- Collection bars
JAXB outputs something like:
<foo> <id> 123> / id> <name> file_name </name> </foo> <- note the absence of the column attribute
Which is problematic, as the client has no reasonable reason to believe that Foo has bars, unless it βjust doesn't knowβ (which seems bad to me). Therefore, although I can imagine, to get a list of bars using:
GET http: // xxx / fooservice / foo / 121 / bars
How does the client know that Foo has bars if the output of the object says nothing about it? Now, assuming that the client is actually getting the list, then it seems that operations with the entity will look something like this:
GET / DELETE / UPDATE http: // xxx / fooservice / foo / 121 / bar / 435
which will gain access to Bar 435 owned by Foo 121.