The path and query part of IRIs are up to you. The path is for hierarchical data, like api/version/module/collection/item/property
, the query is for non-hierarchical data, like ?display-fields="id,name,etc..."
or ?search="brown teddy bear"&offset=125&count=25
, etc...
What you have to keep in mind, that you are working with resources and not operations. So the IRIs are resource identifiers, like DELETE /something
, and not operation identifiers, like POST /something/delete
. You don't have to follow any structure by IRIs, so for example you could use simply POST /dashuif328rgfiwa
. The server would understand, but it would be much harder to write a router for this kind of IRIs, that's why we use nice IRIs.
What is important that a single IRI always belongs only to a single resource. So you cannot read cat properties with GET /cats/123
and write dog properties with PUT /cats/123
. What ppl usually don't understand, that a single resource can have multiple IRIs, so for example /cats/123
, /cats/name:kitty
, /users/123/cats/kitty
, cats/123?fields="id,name"
, etc... can belong to the same resource. Or if you want to give an IRI to a thing (the living cat, not the document which describes it), then you can use /cats/123#thing
or /users/123#kitty
, etc... You usually do that in RDF documents.
What should be URI structure be if I want to be able to fetch contact
by either ID or Alias?
It can be /api/contacts/name:{name}
for example /api/contacts/name:John
, since it is clearly hierarchical. Or you can check if the param contains numeric or string in the /api/contacts/{param}
.
You can use the query too, but I don't recommend that. For example the following IRI can have 2 separate meanings: /api/contacts?name="John"
. You want to list every contact with name John, or you want one exact contact. So you have to make some conventions about this kind of requests in the router of your server side application.