Title: WP_REST_Request::from_url
Published: April 12, 2016
Last modified: April 28, 2025

---

# WP_REST_Request::from_url( string $url ): 󠀁[WP_REST_Request](https://developer.wordpress.org/reference/classes/wp_rest_request/)󠁿|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#wp--skip-link--target)

Retrieves a [WP_REST_Request](https://developer.wordpress.org/reference/classes/wp_rest_request/)
object from a full URL.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#parameters)󠁿

 `$url`stringrequired

URL with protocol, domain, path and query args.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#return)󠁿

 [WP_REST_Request](https://developer.wordpress.org/reference/classes/wp_rest_request/)
|false [WP_REST_Request](https://developer.wordpress.org/reference/classes/wp_rest_request/)
object on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#source)󠁿

    ```php
    public static function from_url( $url ) {
    	$bits         = parse_url( $url );
    	$query_params = array();

    	if ( ! empty( $bits['query'] ) ) {
    		wp_parse_str( $bits['query'], $query_params );
    	}

    	$api_root = rest_url();
    	if ( get_option( 'permalink_structure' ) && str_starts_with( $url, $api_root ) ) {
    		// Pretty permalinks on, and URL is under the API root.
    		$api_url_part = substr( $url, strlen( untrailingslashit( $api_root ) ) );
    		$route        = parse_url( $api_url_part, PHP_URL_PATH );
    	} elseif ( ! empty( $query_params['rest_route'] ) ) {
    		// ?rest_route=... set directly.
    		$route = $query_params['rest_route'];
    		unset( $query_params['rest_route'] );
    	}

    	$request = false;
    	if ( ! empty( $route ) ) {
    		$request = new WP_REST_Request( 'GET', $route );
    		$request->set_query_params( $query_params );
    	}

    	/**
    	 * Filters the REST API request generated from a URL.
    	 *
    	 * @since 4.5.0
    	 *
    	 * @param WP_REST_Request|false $request Generated request object, or false if URL
    	 *                                       could not be parsed.
    	 * @param string                $url     URL the request was generated from.
    	 */
    	return apply_filters( 'rest_request_from_url', $request, $url );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/class-wp-rest-request.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api/class-wp-rest-request.php#L1044)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api/class-wp-rest-request.php#L1044-L1079)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#hooks)󠁿

 [apply_filters( ‘rest_request_from_url’, WP_REST_Request|false $request, string $url )](https://developer.wordpress.org/reference/hooks/rest_request_from_url/)

Filters the REST API request generated from a URL.

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_REST_Request::__construct()](https://developer.wordpress.org/reference/classes/wp_rest_request/__construct/)`wp-includes/rest-api/class-wp-rest-request.php` |

Constructor.

  | 
| [wp_parse_str()](https://developer.wordpress.org/reference/functions/wp_parse_str/)`wp-includes/formatting.php` |

Parses a string into variables to be stored in an array.

  | 
| [untrailingslashit()](https://developer.wordpress.org/reference/functions/untrailingslashit/)`wp-includes/formatting.php` |

Removes trailing forward slashes and backslashes if they exist.

  | 
| [rest_url()](https://developer.wordpress.org/reference/functions/rest_url/)`wp-includes/rest-api.php` |

Retrieves the URL to a REST endpoint.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  |

[Show 3 more](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#)

| Used by | Description | 
| [WP_REST_Server::get_target_hints_for_link()](https://developer.wordpress.org/reference/classes/wp_rest_server/get_target_hints_for_link/)`wp-includes/rest-api/class-wp-rest-server.php` |

Gets the target hints for a REST API Link.

  | 
| [WP_REST_Server::embed_links()](https://developer.wordpress.org/reference/classes/wp_rest_server/embed_links/)`wp-includes/rest-api/class-wp-rest-server.php` |

Embeds the links from the data into the request.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_request/from_url/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_request%2Ffrom_url%2F)
before being able to contribute a note or feedback.