Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Data retrieving routes in rest.module should be bound to the supported format. Currently this is JSON-LD only. Example: GET with Accept: application/xml should return 404. Same for HEAD. All other HTTP methods do not return anything in out current architecture, so they should handle requests regardless of the accept headers.
Work is done in the media-accept-1846582 branch in the REST sandbox.
Comment | File | Size | Author |
---|---|---|---|
#19 | rest-media-1846582-19.patch | 10.47 KB | klausi |
#19 | rest-media-1846582-19-interdiff.txt | 3.09 KB | klausi |
#13 | rest-media-1846582-13.patch | 9 KB | katbailey |
#13 | interdiff.txt | 5.09 KB | katbailey |
#5 | rest-media-1846582-5.patch | 11.44 KB | klausi |
Comments
Comment #1
klausiFirst patch: Implemented media type matching in REST routes, added jsonld event subscriber.
Interdiff is against the issues mentioned in the summary, please review that.
Comment #2.0
(not verified) CreditAttribution: commentedadded rest GET issue dependency.
Comment #3
klausiFixed partial media type matcher simpletests.
Comment #4
klausiSimple reroll, after #1834288: RESTfully request an entity with JSON-LD serialized response got committed. No other changes.
Comment #4.0
klausiadded sandbox link
Comment #5
klausiPatch does not apply anymore, rerolled.
Comment #7
klausi#5: rest-media-1846582-5.patch queued for re-testing.
Comment #9
klausi#5: rest-media-1846582-5.patch queued for re-testing.
Comment #11
Crell CreditAttribution: Crell commentedMicro-optimization: Only call getRequest() once and just call setFormat() on that twice. (Someone should file an issue upstream to make setFormat() chainable...)
Why are only GET/HEAD routes restricted? Shouldn't PUT and POST also be Accept-aware?
It looks like the only difference between these two sections is the _format requirement. That's easy to add via ->addRequirement(), so let's eliminate the duplication here and just wrap the if statement around that.
Comment #12
moshe weitzman CreditAttribution: moshe weitzman commentedI reran the tests locally and get the same errors. When run locally, there is a Verbose message which gives the Fatal Error. Hope this helps:
Comment #13
katbailey CreditAttribution: katbailey commentedThis patch had the unlucky fate of exposing an existing bug in core, simply in virtue of its bringing into existence for the first time a module that provides an event subscriber and is required by another module. To see that this is the circumstance under which the failures occur, make ban module (which also provides an event subscriber) a requirement of some other module and watch this test explode in a similar manner.
@klausi, I should have spotted this when you asked me about it the other day, because the truth is I had come across this bug in the extension handler patch and fixed it there, but didn't put two and two together. The short explanation of why this happens is that the container.modules parameter doesn't get set properly during module_enable(), but the only time we even use that parameter is when we register module namespaces in the kernel before it gets the list of enabled modules from the config service - and the very act of looking up a config object causes an event to be triggered... but the module namespaces for the event subscribers have not been registered yet.
This should fix it. I also addressed @Crell's points in #11 (hopefully correctly!) apart from the question about PUT/POST because I don't know the answer.
Comment #14
katbailey CreditAttribution: katbailey commentedComment #15
katbailey CreditAttribution: katbailey commentedOh, what did not get captured in the interdiff is the fact that I left out the changes to core/lib/Drupal/Core/Routing/MimeTypeMatcher.php and core/modules/system/lib/Drupal/system/Tests/Routing/MimeTypeMatcherTest.php because it looks like they were solved already in a different issue - is that correct?
Comment #16
scor CreditAttribution: scor commented@katbailey yes, the hunks of the 2 MimeTypeMatcher files have been committed in the meantime.
Comment #17
klausiThanks katbailey, you saved my day!
@Crell: in my current default API design data writing operations do not return anything, therefore the Accept headers can be ignored for them. If a resource plugin wishes to handle that differently it can overwrite the routes() method and bind its POST route for example.
Otherwise this looks RTBC to me, I'm not going to set the status since I originally wrote most of this patch.
Comment #18
klausiAlso tagging for Crell.
Comment #19
klausiRerolled patch after #1839346: REST module: POST/create was committed.
Comment #20
moshe weitzman CreditAttribution: moshe weitzman commentedNice teamwork, folks.
Comment #21
Dries CreditAttribution: Dries commentedCommitted to 8.x. Thanks!
Comment #22
catchWhat was this change for?
Comment #23
katbailey CreditAttribution: katbailey commented@catch see #13 for a not very in-depth explanation of why this was needed - let me know if you need more info. Is the change problematic?
Comment #24.0
(not verified) CreditAttribution: commentedRemoved dependencies.