Skip to content
This repository has been archived by the owner on Sep 24, 2018. It is now read-only.

Introduce rest_do_request() for making REST requests internally #1333

Merged
merged 3 commits into from Jun 8, 2015

Conversation

danielbachhuber
Copy link
Member

Routing requests through the server in a RESTful manner permits us to
de-couple controllers from one another, permitting subclassing, etc. It
also ensures all of the appropriate permission and validation checks are
run on each internal request.

See #1218

Routing requests through the server in a RESTful manner permits us to
de-couple controllers from one another, permitting subclassing, etc. It
also ensures all of the appropriate permission and validation checks are
run on each internal request.
@danielbachhuber
Copy link
Member Author

@WP-API/amigos How do you feel about this?

$get_request = new WP_REST_Request( 'GET', rest_url( 'wp/v2/' . $this->get_post_type_base( $this->post_type ) . '/' . $post->ID ) );
$get_request->set_param( 'context', 'edit' );
$response = $this->prepare_item_for_response( $post, $get_request );
$response = rest_do_request( 'GET', '/wp/v2/' . $this->get_post_type_base( $this->post_type ) . '/' . $post->ID, array( 'context' => 'edit' ) );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if I could pass any arbitrary path, including one prepared with rest_url()

@joehoyle
Copy link
Member

joehoyle commented Jun 8, 2015

Per my Slack feedback, I'd like to see it return a WP_Error on an error response, so all my error checking code would be the same as other error checking code. For example:

$request = rest_do_requests( '/wp/v1/posts' );

if ( is_wp_error( $request ) ) {
    return $request;
}

danielbachhuber pushed a commit that referenced this pull request Jun 8, 2015
Introduce `rest_do_request()` for making REST requests internally
@danielbachhuber danielbachhuber merged commit 3035bdf into develop Jun 8, 2015
@danielbachhuber danielbachhuber deleted the 1218-do-rest-request branch June 8, 2015 23:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants