Getting the same error on accessing nodes - node/{node}?_format=json
{"message":"Not acceptable format: json"}
Drupal Version - 8.2.3
ResUI - 8.x-1.13
Same appears - node/{node}?_format=XML
Attaching UI configuration screenshot.
Could be related to changes in this issue - #2758563: Handle core 8.2.x changing REST configuration to use configuration entities

| Comment | File | Size | Author |
|---|---|---|---|
| #54 | innerdiff-2831716-45-54.txt | 2.1 KB | clemens.tolboom |
| #54 | rest_ui_does_not-2831716-54.patch | 19.25 KB | clemens.tolboom |
| #50 | Selection_003.jpg | 141.16 KB | juampynr |
| #50 | Selection_002.jpg | 138.61 KB | juampynr |
| #45 | support_resource_granularity_2831716_45.patch | 19.56 KB | wim leers |
Comments
Comment #2
gvsoIt seems the problem occurs due to a wrong settings configuration
This doesn't work
But changing this make it work
Comment #3
cruno commentedI had a similar issue. Rest UI would set the "supported_auth" but not the "authentication" portion of the config. This caused all POST requests to fail because it would try to check with basic_auth instead of cookie, except I wasn't using basic_auth.
Documented here:
https://www.drupal.org/node/2831251#comment-11813795
Comment #4
imen ch commentedFor drupal 8.2 install the module REST UI 8.x-1.x-dev i have problems with the REST UI module 8.x-1.13, resolved by the dev version module
Comment #5
gvsoAs today, it seems there's no a difference between both branches. After downloading the module using git
git diff 8.x-1.13 8.x-1.xdoesn't output anythingIn fact, 8.x-1.13 was released after the last commit to the dev version
Comment #6
gvsoI've just inspected the code and it seems the issue is produced due to the settings in rest.resource.entity.node.yml which are not changed when editing the configuration with REST UI
Comment #7
gvsoThe problem with nodes occurs because when installing the rest module, the entity.node REST resource configuration is created with 'resource' granularity. However, REST UI uses 'method' granularity. This patch fixes the issue.
Comment #8
gvsoComment #9
clemens.tolboomComment #10
clemens.tolboomI cannot reproduce using
- Drupal 8.3.x
- Rest UI 8.x-1.x
using Basic Auth. I've tested with
curl --user admin:admin --header 'Accept: application/json' --request GET 'http://drupal.d8/node/1?_format=json'[edit]
My config is
[/edit]
Comment #11
gvsoOh, it seems I generated the patch wrongly. Sorry for that.
@clemens.tolboom, I don't know if the default settings were changed in 8.3.x since I haven't checked this issue again. The problem was that granularity was set to "resource" by default in core. However, Rest UI relies on adding settings to every method. I'll check if the default configuration was changed in core and let you know.
Comment #12
gvsoCore still uses 'resource' as the default granularity when installing rest module. However, this configuration will only be added if the dependencies are enabled. In this case if you enable hal, basic_auth and node, this configuration, which uses 'resource' as granularity, will be added.
If you only install rest_ui, rest, and serialization, you shouldn't get this issue. Yet I guess many site builders might tend to enable http authentication and hal along with rest. Then, they will have this issue
Comment #13
wim leersHow is it possible that #2758563: Handle core 8.2.x changing REST configuration to use configuration entities did not fix this?
… installed this myself. And indeed, WTF, it does not work correctly at all.
is displayed like this:
It's this module's responsibility to nudge people to use the simpler, more maintainable, more easily configurable approach: resource-level granularity. The method-level granularity should be an advanced option, and preferably would not even be exposed in the UI.
Comment #14
wim leersComment #15
gvsoThis patch fixed the issue in a project I worked on. I don't know if it's the best approach as it expects that the settings form for nodes will be saved before affecting the default Drupal configuration.
Comment #16
wim leersIt does not.
The UI itself needs to be changed.
Comment #17
rogierbom commentedActually, a lot of work still needed to be done to support resource granularity. The attached patch adds the following:
- A select box on the form to choose between resource an method granularity, resource being the default
- Correctly rebuilding the form based on the granularity selection
- Correctly loading defaults for existing configs
- Form validation for resource granularity
- Submit handling for saving resource granularity
- Correct displaying of resource granularity on the resource list page
Comment #18
rogierbom commentedComment #19
finneHere is some review feedback. I did not test the patch extensively. Someone more familiar with the expected functionality might do this.
- Comments are running beyond 85 chars, mainly due to a reformat that aligns function parameter annotations.
- Normal code is restricted to 85 char lines, reducing legibility.
- style attributes in code: RestUIForm.php:218: better to add a class, and make style changes in your theme.
- array() and [] used inconsistently. Use only [] as per D8 coding standards.
Comment #20
finneComment #21
wim leers#17 was almost working. First, let's revert automatic IDE changes. Those changes are very distracting.
Also rebased, there was a conflict due to recent changes.
Comment #22
wim leersThis is all that was missing. With this, everything works!
Comment #26
wim leersThis is another automatic IDE-made change.
===
This can be made much clearer by having separate helper methods, and then calling those from here.
Strange indentation here.
Two newlines, should be one.
Fixed all that.
Comment #28
rogierbom commentedYeah, somehow phpStorm messed things up a lot, and I missed that when submitting the patch. Thanx for your help!
Comment #29
clemens.tolboomI did a clean install yesterday using D 8.3.x + Rest UI which worked out of the box. So how can I reproduce this?
Comment #30
rogierbom commentedTests needed updating too. The updated test exposed a small issue with the form validation, I fixed this in the supplied patch.
Also, by updating the existing configuration an issue occurred when switching granularity, because the structure of the old granularity was kept. I suggest we only use the existing configuration to pre-fill the form values, and re-generated the configuration after submit based on the form values. Supplied patch also covers this.
Comment #31
rogierbom commented@clemens.tolboom: The module works, but after saving you end up with a resource config with "Method" granularity. There is no way to create a resource config with "Resource" granularity, even though this is the default in Core.
Comment #32
clemens.tolboomSo the issue summary is out of date I guess right?
Comment #33
clemens.tolboomPatch looks ok to me. I'd like to change the text on ie http://drupal.d8/admin/config/services/rest/resource/entity%3Anode/edit
That text should now contain something about the Granularity I guess. As this is now marked as critical it is not per se needed now. Is it worth a new issue?
Comment #34
rogierbom commentedYes, I think it would be better to create a separate issue for updating the description. Would be nice to finally have this in.
Comment #35
wim leers#30: awesome work, thank you!
I'm going to continue my patch reviews now.
Actually, rather than updating this code, we can simply delete it.
Because it's completely wrong, and leads to wrong information being displayed in the UI.
The existing code is saying "if no supported formats are specified, all formats are supported", and the same for authentication mechanisms. But this is not true, and has been wrong since #2065193: supported_formats and supported_auth should work in the same way. That was committed on December 1, 2013. And therefore REST UI has been extremely misleading since then.
Fixing that. (Note that we could move this change to a separate issue, if a maintainer asks that, I'd be happy to oblige. Because this is kind of scope creep. But this should be fixed, otherwise we're just making the problem bigger.)
Comment #36
wim leers(Continuing my review+refactor spree.)
Unnecessary change here.
Probably also made by IDE.
This comment doesn't belong to this code block, it belongs to the next code block.
Let's move this first code block to a helper method, that will make the code more legible too.
hasValue()===
This wrapping is insane.
Also, we repeat the same expression 4 times!
Comment #37
wim leersI'll continue in the morning!
However, if the module maintainers would like to land this already, I'm fine with that! We can continue refactoring later on.
Comment #38
wim leersTime to clean this one up.
Again, reverting unwanted wrapping introduced by somebody's IDE.
And again introducing separate helper methods for both types of granularity, to make the code more legible & maintainable.
The result is that the original
validateForm()method's body remains 99% identical, it's just been moved to a separate helper method :)Makes the patch much easier to understand!
Comment #39
wim leersI added this, but did not fix the docblock.
Made me realize the parameters make a bit more sense in the other order, so fixed that too.
Can be simplified to just
::processAjaxForm.This… does not make sense. We should set it to a valid value right away, or otherwise not set it at all. It will be overwritten at a next step anyway.
These docs aren't entirely accurate.
The 'method' granularity function explicitly creates a
$configurationarray to update, the 'resource' one does not, it appends to a non-existing array created out of thin air. Let's make this consistent.Should link to the interface constants.
Comment #40
wim leersThe changes in the
::buildForm()method are unwieldy: they're massive. Let's again apply the same strategy: two helper methods.That means the vast majority original code remains in the same place, just in a different method (a helper method) instead of in the "main"
buildForm()method.Then we again call either one of the helpers.
In this case it's definitely easier to review this by comparing how
RestUIFormis modified in #39's patch versus how it's modified in this patch. Reading the interdiff is not going to make it very clear what we gain by doing this.Comment #41
wim leersAnd some last nits:
If method, if resource, if method.
Let's put "resource" first always, because that's the default since 8.3.
We can make the patch a bit smaller by renaming
$valuesto$settings.Comment #42
wim leersI think this is ready now. This patch makes the REST UI module do the right thing. And with my refactoring, its scope of changes is now minimized.
Lots of improvements are still possible to
RestUIForm, and we should do those, but we should do them in separate issues.This patch impacts the REST Experience because virtually all D8 sites that use REST, configure it through this module. And this module, to this day, is encouraging the wrong type of configuration: the overly specific one, which is unnecessarily complex, and unnecessarily brittle. Which is why we introduced "resource" granularity in the first place. The sad reality is that likely most D8 sites created since 8.2.0 did not take advantage of that simply because REST UI did not support it.
With this patch, REST UI finally encourages the simpler, more reliable default type of configuration.
Comment #43
wim leersAn important next step after this is converting every 'method' granularity REST resource config entity that can be converted to 'resource' granularity. For that, I created #2869443: REST UI has been creating 'method' granularity configuration: provide update path to automatically convert to 'resource' granularity where possible.
Comment #44
rogierbom commentedFound one last issue. The form that is build defaulted to 'method' granularity, while the granularity select box defaults to 'resource'. This was giving weird behaviour when submitting new resources without switching the granularity.
Also updated the test to validate that the 'resource' granularity form is build by default.
Comment #45
wim leersGreat find!
If this is the solution for #44, then it points to a deeper problem: that the default granularity is not computed correctly. This code should not be the fix. Let's fix the root cause.
Thanks for expanding the test coverage!
Comment #46
rogierbom commentedThat's actually how I fixed it initially :) I agree that getGranularity() should return 'resource' by default if nothing has been set yet. But shouldn't the form logic work the same way? Return the 'resource' granularity form unless 'method' granularity has explicitly been requested?
Comment #47
wim leersNo, the form logic should be as simple as possible. Which means that
$granularityshould be either'method'or'resource'. Not'method'or'resource'orNULL. That's what #45 fixes.Comment #48
rogierbom commentedI didn't mean we should handle
NULLin the form logic, just suggesting to make the 'resource' form returned by default. But if the granularity is always computed correctly that's not really an issue. As far as I'm concerned, this is RTBC!Comment #49
wim leersExactly!
And YAY :)
Comment #50
juampynr commentedLooking at the patch (AWESOME WORK BOTH OF YOU!), while I do some reading, can you help me to make this UI for informative so an administrator can understand what does imply to choose between Resource and Method?
Comment #51
clemens.tolboom@juampynr I agree with your findings. Let's create a new issue for that. I'll commit this one.
Comment #52
clemens.tolboomPatch does not apply due to #2851126: The UI says "disable", but it's really "delete"
Comment #53
clemens.tolboomComment #54
clemens.tolboomComment #55
clemens.tolboom@juampynr added the explanation issue here #2872299: Move granularity away into an 'Advanced' tab
Comment #56
wim leersThanks for the reroll! Commented on the follow-up :)
Comment #58
clemens.tolboomThanks!
Comment #59
juampynr commentedThanks for moving this forward!
Comment #60
rogierbom commentedYeah! :D
Comment #61
wim leersYAY!
Comment #62
wim leersNow let's do #2869443: REST UI has been creating 'method' granularity configuration: provide update path to automatically convert to 'resource' granularity where possible and then tag a release!? :)