Drupal 8 - retrieving URI of current request

If you're used to relying on [code]$_GET['q'][/code] from Drupal 7 (& earlier), you might be in for a surprise with Drupal 8, as [code]$_GET['q'][/code] is no longer defined for any request. Instead, Drupal 8 ships with a series of helper functions:

current_path() - returns the internal Drupal path (ex. [code]node/123[/code])

request_path() - returns the alias (ex. [code]blog/my-post[/code])

base_path() - returns the base path for your Drupal site (ex. [code]/mysite/[/code], if your site is accessible at [code]foo.com/mysite[/code])

request_uri() - returns the full URI, including base path, alias, and any query arguments (ex. [code]/mysite/blog/my-post?foo=bar[/code])