> For the complete documentation index, see [llms.txt](https://docs.hivepress.io/developer-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hivepress.io/developer-docs/framework/components/request.md).

# Request

This component implements callbacks and methods for managing the page request context. With the request context, you can get the request-specific data anywhere in the code rather than passing it to each function that runs during a request.

### Request context <a href="#bkmrk-request-context" id="bkmrk-request-context"></a>

To set a request context value, call the `set_context` method with the key and a value:

```php
hivepress()->request->set_context( 'custom_key', $value );
```

Once the context value is set, you can get it anywhere by calling the `get_context` method:

```php
$value = hivepress()->request->get_context( 'custom_key' );
```

Use the `hivepress/v1/components/request/context` hook that filters the request context array if you need to set some context values on every page load. There are also a few pre-defined context values. For example, you can get the current user object this way:

```php
$user = hivepress()->request->get_user();
```

If the current user is logged in, the `User` [model](/developer-docs/framework/models.md) object is returned. Also, you can get the current page number for paginated queries:

```php
$page = hivepress()->request->get_page_number();
```

### Query variables <a href="#bkmrk-query-variables" id="bkmrk-query-variables"></a>

To get a HivePress-specific [query variable](https://developer.wordpress.org/reference/functions/get_query_var/) (prefixed with `hp_`), call the `get_param` method with the variable name:

```php
$value = hivepress()->request->get_param( 'custom_name' );
```

You can also call the `get_params` method to get an array of all the HivePress query variables.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.hivepress.io/developer-docs/framework/components/request.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
