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.
Wouldn't /jsonapi/node/article
be a whole lot more logical than /api/node/article
?
Comment | File | Size | Author |
---|---|---|---|
#21 | prefix_2838580-20.patch | 25.1 KB | Wim Leers |
|
Comments
Comment #2
Wim LeersRepurposing this for removing the
prefix
configuration.Comment #3
Wim LeersThis just removes the configurable 'prefix'.
Comment #5
Wim LeersHah and this one failed because it builds on top of #2838630: Remove the concept of "enabledness" from the JSON API module, rely on the Entity Access API instead. Rebasing on HEAD instead. That means those patches will conflict.
Comment #6
Wim LeersAnd this reroll now also changes the non-configurable prefix from
/api
to/jsonapi
.Comment #7
Wim LeersUpdating issue title to reflect scope of #6. If you don't want to rename this path, use the patch in #5. But if we're ever going to rename this, it's now.
Comment #9
Wim LeersMissed one spot for #6.
Comment #10
Wim LeersThis is blocking #2831134: Remove configurable 'id_field': always use UUID, because they will conflict and this one is ready, the other one is not.
Comment #11
Wim Leers@e0ipso: you can choose between #5 (only remove configuration) and #9 (also change URL/path).
Comment #12
GrandmaGlassesRopeMan@Wim Leers
Thanks for brining this up. This change feels necessary to make the api more accessible to outside/first time users. I am +1 on changing the prefix to
jsonapi
fromapi
. I would however prefer/{entity type}/{bundle}/{uuid}
with anAccept
header, but I understand that it may not be currently feasible due to a bunch of outside issues.Comment #13
killua99 CreditAttribution: killua99 commentedI like the idea to change the default prefix to /jsonapi rather /api. But I still feel the need to keep it as a config value, to be able to change it if someone want to use something more custom / project related. The this will come back at core when the module hit Experimental State.
Comment #14
hampercm CreditAttribution: hampercm at Acquia commented+1 for changing the prefix from 'api' to 'jsonapi' And yes, having the "Accept" header work would be wonderful.
Comment #15
GrandmaGlassesRopeMan@killua99
I'm not totally opposed to having this as a config value. However keeping it fixed will provide a more consistent experience for users of a JSON-API based API across a number of different Drupal sites.
Comment #16
hampercm CreditAttribution: hampercm at Acquia commented@killua99 @drpal I, too, like the idea of removing the option to change the prefix. Using the /jsonapi URL prefix follows Drupal best-practices of using the module's name as the prefix for its custom routes, so collisions will hopefully be minimal. And, if someone really needs to change the route prefix on a particular site, it is possible to alter existing routes.
Comment #17
Wim Leers@killua99: if you want to change the prefix: use a
\Drupal\Core\Routing\RoutingEvents::ALTER
event subscriber! :)Comment #18
hampercm CreditAttribution: hampercm at Acquia commentedI got the OK from e0ipso on IRC to move ahead with #9: removing config and changing the URL prefix to /jsonapi.
This looks very good; the hard-coded prefix makes route names much cleaner! Two small issues found in review:
1. The README.md file still refers to URLs with the /api prefix
2. jsonapi/tests/src/Unit/Context/CurrentContextTest.php:71 uses a route for
'/api/articles'
in its tests. Not sure fi this makes any difference, but may want to change that to use something like /jsonapi/node/article.Once those are fixed, I think this can be RTBC.
Comment #19
hampercm CreditAttribution: hampercm at Acquia commentedComment #20
hampercm CreditAttribution: hampercm at Acquia commentedUgh, sorry for the extraneous comments :P
Comment #21
Wim LeersDone!
Comment #23
e0ipsoI did a quick review and all looks good. So much easier when you get stuff RTBCed :_)
This is merged.
Comment #24
Wim LeersThanks! Already unpostponed #2831134 and uploaded the patch for testing that should come back green: #2831134: Remove configurable 'id_field': always use UUID.
Comment #25
dagmarThis change requires an update at the docs: https://www.drupal.org/node/2804085
I think would be nice to document how to change the prefix like Wim indicated in #17.
Comment #26
hampercm CreditAttribution: hampercm at Acquia commentedDocumentation updated! It might make sense to refactor the documentation and remove the page at https://www.drupal.org/node/2804085 completely, or reuse it to give a detailed example of altering the routes.
Comment #27
e0ipsoIt's worth noting that you can detect if a route is managed by JSON API by checking:
Comment #29
gerzenstl CreditAttribution: gerzenstl at 42mate commentedI tryied the following implementation change the URL prefix and works fine:
any suggestion is welcome.
Comment #30
DanBerk4 CreditAttribution: DanBerk4 commented@ #29 This works for the collection/list request, but breaks for individual item request. i.e. /api/v1/node/11 will return a 404 instead of the node with id 11
Comment #31
bojanz CreditAttribution: bojanz at Centarro commentedNote that JSON API nowadays has a jsonapi.base_path container parameter.
I too wanted to replace /jsonapi with /api/v1, and all it took was this in my service provider:
(This issue is ranked high in a Google search, so I figured I'd leave a note)
Comment #32
Wim Leers#31: thanks! :)
Note that if you want to customize this at the site level rather than in a (site-specific) module, you can do so by providing a
services.yml
file in yoursites/yoursite.com/
: