Opened 10 years ago
Closed 10 years ago
#34707 closed enhancement (wontfix)
Separate out the namespace from the path in rest_url
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | REST API | Keywords: | dev-feedback |
Focuses: | Cc: |
Description
From API#1504, discussed briefly in #34302; PR on https://github.com/WP-API/api-core/pull/4.
Everywhere else we deal with URLs, we specify namespace and route separately, except when generating URLs.
This changes to no longer match the format of get_home_url
/get_site_url
/get_admin_url
(blog ID, path, scheme), however there are already a few that don't follow this format:
get_dashboard_url
(user, path, scheme)get_edit_profile_url
(user, scheme)get_site_icon_url
(size, URL, blog).
This also breaks compatibility with existing versions of the API.
If we want to pull the trigger, we need to do it now.
Change History (7)
#2
@
10 years ago
Aside from consistency, are there any pragmatic advantages to separating the namespace and path in get_rest_url()
? I can't think of any.
Everywhere else we deal with URLs, we specify namespace and route separately, except when generating URLs.
I think this is fine. Elsewhere, specifying the namespace and route separately has a pragmatic application. Given get_rest_url()
is largely just a wrapper for home_url()
, I don't see the inconsistency as an issue needing to be fixed.
#3
@
10 years ago
@rmccue @danielbachhuber I believe the overall issue here is the confusion developers experience with the inconsistencies between register_rest_route()
and get_rest_url()
.
I am too close to the code to understand if accepting an array and a string would reduce any confusion. I am okay with wontfix
ing this because of the BC breakage and unclear path forward.
#4
@
10 years ago
The main use case I can think of is in controllers, you may have the namespace and route separate already, so to generate URLs, you'd need to build the string yourself. I don't think that's a huge issue.
If we did allow an array, we'd have something like...
register_rest_route( $this->namespace, $this->route, array( /* ... */ ) ); // Current style $url = get_rest_url( $this->namespace . '/' . $this->route ); // New style $url = get_rest_url( array( $this->namespace, $this->route ) );
@wonderboymusic I think it was you that originally suggested splitting the args here. Was there a particular reason for that?
#5
@
10 years ago
@rmccue Here are @wonderboymusic's comments that sparked this fire: https://wordpress.slack.com/archives/core-restapi/p1439328572003434
@danielbachhuber @rachelbaker @joehoyle I'm not sure I want to change this and break BC so late; what if we accept both a string (of
namespace/route
) and and array ofnamespace, route
? Taking a string lets us keep BC and is relatively concise, array-form means you don't have to build it yourself. Win-win?