Search code examples
restopenrasta

OpenRasta accessing sub elements


I have a design of a person having a collection of subjects like Person ---> Subject (1 to many)

If I access a person with an Id of 1 (http://localhost/person/1), it will show all the person's details and the collection details.

How do I design a URL for just accessing the subjects for the person? Should it be http://localhost/person/1/subjects? Can I post to that URL to add subjects? Can I put to that URL to update the subjects?

What handler should handle subjects of a person? Should it be a subject handler with Get and a personid parameter or a person handler returning a collection of subjects with a return method of subjects?


Solution

  • From a ReST perspective it doesn't matter in the slightest, URIs are just opaque identifiers so how they're structured is an orthogonal concern.

    From an OR point of view, you can just register AtUri("/person/{id}/subjects/{subjectid}") and have your method with a signature of Post(int id, int subjectid), that will work jut fine.

    Now from a design perspective, anything that is to be accessed independently is another resource, so the collection of subjects and each subject are independent resources. OR makes a lot of assumptions relying on you mapping each indepednent resource independently, otherwise things like URI creation break quickly.