-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WiP] Simplified REST structures #1990
Conversation
This includes several ideas: 1. In order to ease usage of the REST API for JavaScript but also PHP consumers, simplified media type definitions can be created. 2. Simplified media types are used right beside the original ones which might be valid either infinitely or which might be replaced graduately by the simplified versions (evolution). 3. In the first step, simplified media types are used only to make create/update operations easier in that the data structures they define are easier to create and work with. 4. Also, simplified media types require less information to be present and will be automatically completed with sane default values by the server. In addition, this commit already contains hints on the new concept of "alias URIs" (see next commits in this branch).
Alias URIs permit more user friendly IDs/URLs while maintaining a consistent state throughout caches.
Feedback on simplified ContentCreate in REST APIThese are the initial review comments and braindump about the simplified REST structure. General
Complex ContentCreate-Reques
Proposal: URL Aliasing
|
"title": "This is a title", | ||
"intro": { | ||
"xhtml5edit": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<section xmlns=\"http://ez.no/namespaces/ezpublish5/xhtml5/edit\"><p>Article intro.</p></section>\n", | ||
"xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<section xmlns=\"http://docbook.org/ns/docbook\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:ezxhtml=\"http://ez.no/xmlns/ezpublish/docbook/xhtml\" xmlns:ezcustom=\"http://ez.no/xmlns/ezpublish/docbook/custom\" version=\"5.0-variant ezpublish-1.0\"><para>Article intro.</para></section>\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tobyS do you imply by this, that both xhtml5edit
and xml
values are required or just one of them depending on API consumer needs? I'm asking because if we want to simplify, only one should be required, but both supported (just IMHO).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alongosz The latter one. The attributes set for a field are only determined by the field type.
|
||
A request/response cycle for an alias URI is supposed to be executed as follows: | ||
|
||
:Resource: /content/types/_by_identifier/article |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why you aim to duplicate the existing mechanism for this?
Referring here to ?remoteId
, ?identifier
, ?locationPath
, ?roleId
, ?email
and ?login
, I would have expected the concepts here to extend that for the identified scenarios.
For instance the example here can already be expressed using:
<contentTypeByIdentifier media-type="" href="/api/ezp/v2/content/types{?identifier}"/>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good that you pointed me to this one. Did not see it, yet. I'll dig into how this is realized, because spec is not complete here (missing media types, etc.).
In general, ?something=anything
is a filter on a list, so that might return 0, 1 or even more results, which does not make that a reliable source for referencing a unique item in a link.
But, let's see how it is implemented anyway …
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, the behavior is returning a list, but also throwing 404 if the list is empty. This is not entirely correct from a REST PoV but not worth changing. So, agreed with @andrerom, we should re-use this mechanism for the alias URLs. I'll update the spec and also add some more info on the media types returned by such requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Research on how this is specified/implemented in detail revealed that there is no consistent way, yet: https://gist.github.com/tobyS/c1004831f87291e19662c28a0edef2f2 I recommend switching to redirects everywhere since this seems to be most common and gives only a tiny BC break. With that, we can implement the remaining alias URLs in the same way and allow them to be used by the simplified creates. I'll update the specs and code accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I had redirection in mind here, so just adjusting the semantic to existing examples where redirect is used. And in parallel we can consider fixing existing cases to make api more consistent.
( /cc @bdunogier What do you think? )
Only concern I have with redirect is cache, can we somehow cache them, shortly lived, and even tag them to make sure we purge it on updates? Will Vanish for instance allow that? anyway, that is separate topic probably.
This will be used in parsing simplified content create to resolve the referred resources. Pimping this a little bit gives potential to simplify quite a bit of controller code in REST server, too.
This creates a ResourceResolver with required loading callbacks configured.
Untested due to working outside of vendor/ of ezplatform.
This is basically configuration so it belongs here.
Current state overview
|
.. code:: http | ||
|
||
HTTP/1.1 307 Temporary Redirect | ||
Location: /content/types/23 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: we can cache these with Varnish: http://book.varnish-software.com/4.0/chapters/VCL_Basics.html#the-initial-value-of-beresp-ttl
Assuming we also return cache headers mentioned there, and proper tag header so ezplatform-http-cache can invalidate it (needed if we cache this).
=============================================================== =============================== | ||
Alias URI Target | ||
--------------------------------------------------------------- ------------------------------- | ||
/content/objects/_by_remote_id/<remote-ID> /content/objects/<ID> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weren't this supposed to use same form as /content/types/?identifier=article
referred to above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, missed to update this. Needs to be fixed.
This PR deals to discuss simplified REST structures, based on the initial approach presented here.
The basic idea is to ease usage of the REST API, especially for JSON based clients.
Further TODOs: