after years of absence from web programming I now start to write a new web application from scratch. I learned the ropes of REST and found some helfful presentations and webinars about good and bad "URI styles". But all these tutorials seems to assume that there are only ressources that can be mapped to entitities that persist in a database. If one needs to GET
a HTML (user-friendly) version of something, then the prevalent answer is to use content negiotation via HTTP header fields. The ultimate goal seems to have only URIs that follow the REST paradigm.
But what is the "correct" way to display web pages that cannot be mapped to an entity but are required anyway?
Perhaps I make an example to clarify what I mean. Assume we have a collection Persons
and the entity Person
.
Then we have
POST /Persons/
to create a new person in the collectionDELETE /Person/{id}/
to delete the personPUT /Person/{id}/
to modifiy the person (yes, I know it can also mean to create one)GET /Persons/
to get the list of all personsGET /Person/{id}/
to get an individual person- and so on
With respect to the GET
operations I generally found the advice to use the Accept
and X-Requested-With
header fields of the request to create a response that either returns the "bare" person object in a computer-readable respresentation (i.e. JSON, XML, etc.) or that returns a fully-fledged web page for a browser.
But what is about the PUT
operation. Ultimately, this operation will send a bare person object (i.e. JSON, XLM) that is going to be created, but before this step I need to collect the data from the user. This means I need some empty web form that is just "eye-candy" for the human user. Of course, I could habe something like GET /newPersonForm/
but it seems that this contradict the REST philosophy, because /newPersonForm/
is an URI that only points to some user interface element.
At the moment I see to options:
Use the same name space for both kind of URIs:
POST /Persons/
--> REST apiDELETE /Person/{id}/
--> REST apiPUT /Persons/{id}/
--> REST apiGET /Persons/
--> REST api or UI (after content negiotation)GET /Person/{id}/
--> REST api or UI (after content negiotation)GET /Person/creationForm
--> non-REST, pure UIGET /aboutus
--> non-REST, pure UI, additional company information
Make separate name spaces:
/api/...
--> contains everything for REST/ui/...
--> contains html web pages
With the first approach I feel that it is somebit "unclean". Although the second approach seems cleaner, I see two problems. Firstly, if one follows this approach cleanly, one gets much double URIs, because one dispense with content negiotation and has an UI web page for every REST function. I have GET /api/Person/{id}/
to return a JSON object and GET /ui/Person/{id}
to return a browser version. Secondly, I feel that this approach contradict REST philosophy because search egines and web crawlers cannot understand the structure of the site.
Any recommendations what the best practice is?