PHPackages                             bayfrontmedia/php-http-request - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. bayfrontmedia/php-http-request

ActiveLibrary[HTTP &amp; Networking](/categories/http)

bayfrontmedia/php-http-request
==============================

Easily handle data from incoming HTTP requests.

v3.1.2(1y ago)41.7k↓100%11MITPHPPHP ^8.0

Since Jul 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bayfrontmedia/php-http-request)[ Packagist](https://packagist.org/packages/bayfrontmedia/php-http-request)[ Docs](https://github.com/bayfrontmedia/php-http-request)[ RSS](/packages/bayfrontmedia-php-http-request/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (1)Versions (14)Used By (1)

PHP HTTP request
----------------

[](#php-http-request)

Easily handle data from incoming HTTP requests.

- [License](#license)
- [Author](#author)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)

License
-------

[](#license)

This project is open source and available under the [MIT License](LICENSE).

Author
------

[](#author)

[![Bayfront Media](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)

- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github&utm_medium=direct)
- [Bayfront Media GitHub](https://github.com/bayfrontmedia)

Requirements
------------

[](#requirements)

- PHP `^8.0` (Tested up to `8.4`)

Installation
------------

[](#installation)

```
composer require bayfrontmedia/php-http-request

```

Usage
-----

[](#usage)

**Request methods**

- [validateMethod](#validatemethod)
- [getMethod](#getmethod)
- [isConnect](#isconnect)
- [isDelete](#isdelete)
- [isGet](#isget)
- [isHead](#ishead)
- [isOptions](#isoptions)
- [isPatch](#ispatch)
- [isPost](#ispost)
- [isPut](#isput)
- [isTrace](#istrace)

**Data types**

- [getFile](#getfile)
- [hasFile](#hasfile)
- [getQuery](#getquery)
- [hasQuery](#hasquery)
- [getPost](#getpost)
- [hasPost](#haspost)
- [getServer](#getserver)
- [hasServer](#hasserver)
- [getCookie](#getcookie)
- [hasCookie](#hascookie)
- [getHeader](#getheader)
- [hasHeader](#hasheader)
- [getBody](#getbody)
- [hasBody](#hasbody)

**Specific values**

- [getUserAgent](#getuseragent)
- [getReferer](#getreferer)
- [getIp](#getip)
- [isCli](#iscli)
- [isJson](#isjson)
- [wantsJson](#wantsjson)
- [isHttps](#ishttps)
- [getRequest](#getrequest)
- [getUrl](#geturl)

---

### validateMethod

[](#validatemethod)

**Description:**

Returns valid request method with a fallback to `GET`.

Valid request methods include:

- `CONNECT`
- `DELETE`
- `GET`
- `HEAD`
- `OPTIONS`
- `PATCH`
- `POST`
- `PUT`
- `TRACE`

**Parameters:**

- `$method` (string)

**Returns:**

- (string)

**Example:**

```
use Bayfront\HttpRequest\Request;

echo Request::validateMethod('GET');

```

---

### getMethod

[](#getmethod)

**Description:**

Returns current request method.

**Parameters:**

- None

**Returns:**

- (string)

**Example:**

```
use Bayfront\HttpRequest\Request;

echo Request::getMethod();

```

---

### isConnect

[](#isconnect)

**Description:**

Is current request method `CONNECT`.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::isConnect()) {
    // Do something
}

```

---

### isDelete

[](#isdelete)

**Description:**

Is current request method `DELETE`.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::isDelete()) {
    // Do something
}

```

---

### isGet

[](#isget)

**Description:**

Is current request method `GET`.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::isGet()) {
    // Do something
}

```

---

### isHead

[](#ishead)

**Description:**

Is current request method `HEAD`.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::isHead()) {
    // Do something
}

```

---

### isOptions

[](#isoptions)

**Description:**

Is current request method `OPTIONS`.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::isOptions()) {
    // Do something
}

```

---

### isPatch

[](#ispatch)

**Description:**

Is current request method `PATCH`.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::isPatch()) {
    // Do something
}

```

---

### isPost

[](#ispost)

**Description:**

Is current request method `POST`.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::isPost()) {
    // Do something
}

```

---

### isPut

[](#isput)

**Description:**

Is current request method `PUT`.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::isPut()) {
    // Do something
}

```

---

### isTrace

[](#istrace)

**Description:**

Is current request method `TRACE`.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::isTrace()) {
    // Do something
}

```

---

### getFile

[](#getfile)

**Description:**

Returns value of single `$_FILES` array key in dot notation or entire array, with optional default value.

**Parameters:**

- `$key = NULL` (string|null)
- `$default = NULL` (mixed): Default value to return if array key is not found

**Returns:**

- (mixed)

**Example:**

```
use Bayfront\HttpRequest\Request;

print_r(Request::getFile('profile_photo'));

```

---

### hasFile

[](#hasfile)

**Description:**

Checks if `$_FILES` array key exists in dot notation.

**Parameters:**

- `$key` (string)

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::hasFile('profile_photo')) {
    // Do something
}

```

---

### getQuery

[](#getquery)

**Description:**

Returns value of single `$_GET` array key in dot notation or entire array, with optional default value.

**Parameters:**

- `$key = NULL` (string|null)
- `$default = NULL` (mixed): Default value to return if array key is not found

**Returns:**

- (mixed)

**Example:**

```
use Bayfront\HttpRequest\Request;

print_r(Request::getQuery());

```

---

### hasQuery

[](#hasquery)

**Description:**

Checks if `$_GET` array key exists in dot notation.

**Parameters:**

- `$key` (string)

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::hasQuery('page')) {
    // Do something
}

```

---

### getPost

[](#getpost)

**Description:**

Returns value of single `$_POST` array key in dot notation or entire array, with optional default value.

**Parameters:**

- `$key = NULL` (string|null)
- `$default = NULL` (mixed): Default value to return if array key is not found

**Returns:**

- (mixed)

**Example:**

```
use Bayfront\HttpRequest\Request;

print_r(Request::getPost());

```

---

### hasPost

[](#haspost)

**Description:**

Checks if `$_POST` array key exists in dot notation.

**Parameters:**

- `$key` (string)

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::hasPost('username')) {
    // Do something
}

```

---

### getServer

[](#getserver)

**Description:**

Returns value of single `$_SERVER` array key in dot notation or entire array, with optional default value.

**Parameters:**

- `$key = NULL` (string|null)
- `$default = NULL` (mixed): Default value to return if array key is not found

**Returns:**

- (mixed)

**Example:**

```
use Bayfront\HttpRequest\Request;

print_r(Request::getServer());

```

---

### hasServer

[](#hasserver)

**Description:**

Checks if `$_SERVER` array key exists in dot notation.

**Parameters:**

- `$key` (string)

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::hasServer('SERVER_NAME')) {
    // Do something
}

```

---

### getCookie

[](#getcookie)

**Description:**

Returns value of single `$_COOKIE` array key in dot notation or entire array, with optional default value.

**Parameters:**

- `$key = NULL` (string|null)
- `$default = NULL` (mixed): Default value to return if array key is not found

**Returns:**

- (mixed)

**Example:**

```
use Bayfront\HttpRequest\Request;

print_r(Request::getCookie());

```

---

### hasCookie

[](#hascookie)

**Description:**

Checks if `$_COOKIE` array key exists in dot notation.

**Parameters:**

- `$key` (string)

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::hasCookie('cart_id')) {
    // Do something
}

```

---

### getHeader

[](#getheader)

**Description:**

Returns value of single header array key in dot notation or entire array, with optional default value.

**Parameters:**

- `$key = NULL` (string|null)
- `$default = NULL` (mixed): Default value to return if array key is not found

**Returns:**

- (mixed)

**Example:**

```
use Bayfront\HttpRequest\Request;

print_r(Request::getHeader());

```

---

### hasHeader

[](#hasheader)

**Description:**

Checks if header array key exists in dot notation.

**Parameters:**

- `$key` (string)

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::hasHeader('Content-Type')) {
    // Do something
}

```

---

### getBody

[](#getbody)

**Description:**

Returns content body of a request.

**Parameters:**

- None

**Returns:**

- (string)

**Example:**

```
use Bayfront\HttpRequest\Request;

print_r(Request::getBody());

```

---

### hasBody

[](#hasbody)

**Description:**

Checks if content body of a request exists.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::hasBody()) {
    // Do something
}

```

---

### getUserAgent

[](#getuseragent)

**Description:**

Returns client's user agent.

**Parameters:**

- None

**Returns:**

- (mixed): string|null

**Example:**

```
use Bayfront\HttpRequest\Request;

echo Request::getUserAgent();

```

---

### getReferer

[](#getreferer)

**Description:**

Returns client's referring URL.

**Parameters:**

- None

**Returns:**

- (mixed): string|null

**Example:**

```
use Bayfront\HttpRequest\Request;

echo Request::getReferer();

```

---

### getIp

[](#getip)

**Description:**

Returns the most probable IP of client with optional default value.

**Parameters:**

- `$default = ''` (string): Default IP address to return if none detected

**Returns:**

- (string)

**Example:**

```
use Bayfront\HttpRequest\Request;

echo Request::getIp();

```

---

### isCli

[](#iscli)

**Description:**

Is the request originating from the command line.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::isCli()) {
    // Do something
}

```

---

### isJson

[](#isjson)

**Description:**

Is the `Content-Type` header for this request JSON.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::isJson()) {
    // Do something
}

```

---

### wantsJson

[](#wantsjson)

**Description:**

Does the `Accept` header for this request expect JSON.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::wantsJson()) {
    // Do something
}

```

---

### isHttps

[](#ishttps)

**Description:**

Is connection HTTPS.

**Parameters:**

- None

**Returns:**

- (bool)

**Example:**

```
use Bayfront\HttpRequest\Request;

if (Request::isHttps()) {
    // Do something
}

```

---

### getRequest

[](#getrequest)

**Description:**

Returns array containing details of the client's request, or string of a specific part of the request.

**Parameters:**

- `$part = ''` (string): Which part of the request to return. Leaving this blank will return the entire array.

Valid `$part` values include any of the `PART_*` constants:

- `Requst::PART_METHOD`
- `Request::PART_PROTOCOL`
- `Request::PART_HOST`
- `Request::PART_PATH`
- `Request::PART_QUERY`
- `Request::PART_QUERY_STRING`
- `Request::PART_URL`
- `Request::PART_FULL_URL`

**Returns:**

- (mixed): array|string

**Example:**

```
use Bayfront\HttpRequest\Request;

echo Request::getRequest(Request::PART_URL);

```

---

### getUrl

[](#geturl)

**Description:**

Returns current URL.

**Parameters:**

- `$include_query = false` (bool): Include the query string, if existing

**Returns:**

- (string)

**Example:**

```
use Bayfront\HttpRequest\Request;

echo Request::getUrl();

```

###  Health Score

39

—

LowBetter than 87% of packages

Maintenance43

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~134 days

Recently: every ~174 days

Total

13

Last Release

453d ago

Major Versions

v1.3.0 → v2.0.02020-11-06

v2.1.0 → v3.0.02023-01-26

PHP version history (2 changes)1.0.0PHP &gt;=7.1.0

v3.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ad62c8d0e69358fd63b16fdaa71d5359231cd0cf660bbc3419071dc705c63a8?d=identicon)[bayfrontmedia](/maintainers/bayfrontmedia)

---

Top Contributors

[![robinsonjohn](https://avatars.githubusercontent.com/u/24327848?v=4)](https://github.com/robinsonjohn "robinsonjohn (22 commits)")

---

Tags

cookiedeletegetheadheaderhttpmethodoptionspatchphppostputrequestserversuperglobalurlhttprequesturlphpoptionsserverheadercookiemethodgetpostdeleteputpatchheadsuperglobal

### Embed Badge

![Health badge](/badges/bayfrontmedia-php-http-request/health.svg)

```
[![Health](https://phpackages.com/badges/bayfrontmedia-php-http-request/health.svg)](https://phpackages.com/packages/bayfrontmedia-php-http-request)
```

###  Alternatives

[elementaryframework/water-pipe

URL routing framework and requests/responses handler for PHP

254.2k4](/packages/elementaryframework-water-pipe)[aplus/http

Aplus Framework HTTP Library

2311.6M10](/packages/aplus-http)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
