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.
bshaffer hit a DX issue when testing REST. He tested it without custom config, and JSON worked. Then he added hal_json: TRUE
and the JSON stopped working. This is by design, but it does seem like a DX issue.
He suggested changing the format from:
GET:
hal_json: 'TRUE'
to
GET:
supported_formats:
- hal_json
Comment | File | Size | Author |
---|---|---|---|
#6 | interdiff.txt | 2.55 KB | linclark |
#6 | 2011832-06-rest-config.patch | 2.58 KB | linclark |
#4 | 2011832-04-rest-config.patch | 2.57 KB | linclark |
#3 | 2011832-03-rest-config.patch | 2.57 KB | linclark |
#3 | interdiff.txt | 959 bytes | linclark |
Comments
Comment #1
linclark CreditAttribution: linclark commentedThis patch passes tests. I don't know if this means it works or that we don't have full test coverage.
Comment #1.0
linclark CreditAttribution: linclark commentedUpdated issue summary.
Comment #2
klausiThis will throw PHP notices if the supportedFormats key is not set (all formats allowed).
Same here, right?
Otherwise looks good to me.
Comment #3
linclark CreditAttribution: linclark commentedIn an OR, doesn't it evaluate the first, and if it returns TRUE then it doesn't evaluate the second? Thus, if supportedFormats is not set, it will pass the first condition and not run the second?
I've corrected the other. Eventually, we might want to consider whether this check should go in a method. Can the settings be a configurable with its own methods?
Comment #4
linclark CreditAttribution: linclark commentedTypo will make that last one fail.
Comment #5
klausiRight, the second OR is of course fine.
Although checking these settings is a bit tedious I don't think it warrants the creation of a config entity with a method for REST module.
We need to update the docs at https://drupal.org/documentation/modules/rest after this lands.
Looks RTBC to me!
Comment #5.0
klausicamel case, yay
Comment #6
linclark CreditAttribution: linclark commentedKlaus said in IRC that he preferred supported_formats to supportedFormats, and I agree. I asked alexpott, and he said that was fine, so switching back.
Comment #7
Dries CreditAttribution: Dries commentedIt's not clear how the new format fixes the DX issue. Care to explain a bit better?
Comment #8
linclark CreditAttribution: linclark commentedThe problem was that the user was confused what 'json' => TRUE meant. By explicitly stating that this is a list of supported formats, it makes it clearer that something that if it is not in the list, it is not a supported format. It also makes the API more open to additions later down the road, if we determine we need additional settings for the methods.
Comment #9
alexpottI think we should use YAML commits in the default rest.settings.yml to explain how the file can look like...
Then changes like this become easier to review...
Setting back to needs works because I think this is an ideal place to do this... as we are changing the format... but I really like the change... config files that can be read and the meaning intuited are a good thing.
Comment #10
linclark CreditAttribution: linclark commentedThis is related to another issue... I think that we should enable methods by default on nodes. See #2031647: Provide minimal default rest configuration.
Would it be alright if we address the documentation in that issue?
Comment #11
alexpottOkay after discussing this with @linclark #2031647: Provide minimal default rest configuration will add the docs...
Comment #12
alexpottCommitted 7f2133b and pushed to 8.x. Thanks!
Comment #13
klausiI fixed the example YAML config on https://drupal.org/documentation/modules/rest
Comment #14.0
(not verified) CreditAttribution: commentedUpdated issue summary.