PHPackages                             omaralalwi/laravel-api-helpers - 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. [API Development](/categories/api)
4. /
5. omaralalwi/laravel-api-helpers

ActiveLibrary[API Development](/categories/api)

omaralalwi/laravel-api-helpers
==============================

collection of helpful helper functions for API Requests .

1.0.3(1y ago)1544MITPHPPHP ^7.4|^8.0

Since Mar 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/omaralalwi/laravel-api-helpers)[ Packagist](https://packagist.org/packages/omaralalwi/laravel-api-helpers)[ Docs](https://github.com/omaralalwi/laravel-api-helpers)[ RSS](/packages/omaralalwi-laravel-api-helpers/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)DependenciesVersions (7)Used By (0)

Laravel API Helpers 🚀
=====================

[](#laravel-api-helpers-)

 Laravel API Helpers is a collection of helper functions designed to streamline API development with Laravel. It enables you to easily detect API versions, validate requests, and access useful request details—all while keeping your code clean and maintainable. ✨

 [ ![Latest Version](https://camo.githubusercontent.com/ae9c6f859b163339ac7cc8db0e529becc4b6d4b849ec4a05f8e6efc1d2e0ee12/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6d6172616c616c77692f6c61726176656c2d6170692d68656c70657273) ](https://packagist.org/packages/omaralalwi/laravel-api-helpers) [ ![PHP Version](https://camo.githubusercontent.com/ce0c70c519047d0e507604f03e6e8ae6c27bcc072027e899680d9bf93804dc76/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e342532422d626c7565) ](https://php.net) [ ![License](https://camo.githubusercontent.com/88e1dabf4d223df0950e0985948e231325fefca9fa7fe9e446cf8b1c5e9d9e47/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e) ](LICENSE.md)

🌟 Features
----------

[](#-features)

- **API Version Detection:** Determine the API version from the request URL or headers.
- **API Version Validation:** Check if the current request matches or exceeds a specified API version.
- **API Request Identification:** Identify if a request is targeting the API.
- **Request Helpers:** Retrieve client IP, locale, token, content type, headers, and check for secure requests.
- **Authentication Helpers:** Determine API authentication status and retrieve the authenticated user.

📋 Requirements
--------------

[](#-requirements)

- PHP 7.4 or higher
- Laravel 7.x or higher

🛠️ Installation
---------------

[](#️-installation)

Install the package via Composer:

```
composer require omaralalwi/laravel-api-helpers
```

📦 Usage
-------

[](#--usage)

The helper functions are globally available throughout your Laravel application. You can call them anywhere—controllers, middleware, or routes or blade files.

---

📚 API Helper Functions Guide
----------------------------

[](#-api-helper-functions-guide)

### 🔍 . `get_api_v()`

[](#--get_api_v)

Extracts the API version from the current request by inspecting the URL (e.g., `api/v4`) or the `Accept-Version` header.

```
$apiVersion = get_api_v();
```

---

### ✅ . `is_api_v($version)`

[](#--is_api_vversion)

Determines if the current request is for a specific API version by comparing the detected version with the provided one.

```
// Check if the current API version is 3
if (is_api_v(3)) {
    echo "This is API version 3. ✅";
} else {
    echo "This is not API version 3. ❌";
}
```

---

### ⏫ . `api_v_at_least($version)`

[](#--api_v_at_leastversion)

Checks whether the current API version is at least a specified minimum version.

```
// Verify that the API version is at least version 4
if (api_v_at_least(4)) {
    echo "API version is 4 or higher. 🚀";
} else {
    echo "API version is below 4. Please upgrade.";
}
```

---

### 🌐 . `is_api_request()`

[](#--is_api_request)

Determines whether the current request is an API request by examining the URL, expected JSON responses, and the presence of specific API headers.

```
if (is_api_request()) {
    echo "This is an API request. 🌐";
} else {
    echo "This is not an API request.";
}
```

---

### 📡 . `get_client_ip()`

[](#--get_client_ip)

Retrieves the client's IP address from the current request.

```
$clientIp = get_client_ip();
echo "Client IP: " . ($clientIp ?? "unknown");
```

---

### 🌍 . `get_request_locale()`

[](#--get_request_locale)

Gets the locale from the request's `Accept-Language` header. If not provided, it defaults to the application's locale.

```
$locale = get_request_locale();
echo "Request locale: {$locale}";
```

---

### 🔑 . `get_request_token()`

[](#--get_request_token)

Returns the bearer token from the current request's authorization header.

```
$token = get_request_token();
echo $token ? "Token: {$token}" : "No token found.";
```

---

### 📝 . `get_request_content_type()`

[](#--get_request_content_type)

Retrieves the `Content-Type` header from the current request.

```
$contentType = get_request_content_type();
echo $contentType ? "Content-Type: {$contentType}" : "No Content-Type provided.";
```

---

### 🔒 . `is_secure_request()`

[](#--is_secure_request)

Checks whether the current request is made over a secure HTTPS connection.

```
if (is_secure_request()) {
    echo "Secure HTTPS request detected. 🔒";
} else {
    echo "This is not a secure request.";
}
```

---

### 📋 . `get_request_headers()`

[](#--get_request_headers)

Returns all headers from the current request as an associative array.

```
$headers = get_request_headers();
print_r($headers); // Displays all request headers
```

---

### 🔐 . `is_api_authenticated()`

[](#--is_api_authenticated)

Determines whether the API user is authenticated using the `api` guard.

```
if (is_api_authenticated()) {
    echo "API user is authenticated. 🔐";
} else {
    echo "API user is not authenticated.";
}
```

---

### 👤 . `get_auth_user()`

[](#--get_auth_user)

Retrieves the authenticated user from the default authentication guard.

```
$user = get_auth_user();
echo $user ? "Authenticated user: {$user->name}" : "No authenticated user.";
```

---

### 👥 . `get_api_user()`

[](#--get_api_user)

Returns the authenticated user using the `api` guard.

```
$apiUser = get_api_user();
echo $apiUser ? "API User: {$apiUser->name}" : "No API user authenticated.";
```

---

### Comprehensive Example For All Functions

[](#comprehensive-example-for-all-functions)

copy &amp; past following block, then see outputs in log file

```
$apiHelpers = [
    'API Version'             => get_api_v(),
    'Is API v3?'              => is_api_v(3),
    'API Version At Least 4?' => api_v_at_least(4),
    'Is API Request?'         => is_api_request(),
    'Client IP'               => get_client_ip(),
    'Request Locale'          => get_request_locale(),
    'Request Token'           => get_request_token(),
    'Request Content-Type'    => get_request_content_type(),
    'Is Secure Request?'      => is_secure_request(),
    'Request Headers'         => json_encode(get_request_headers()),
    'Is API Authenticated?'   => is_api_authenticated(),
    'Authenticated User'      => optional(get_auth_user())->name ?? 'No Authenticated User',
    'API Authenticated User'  => optional(get_api_user())->name ?? 'No API User Authenticated',
];

\Log::info('API Helper Functions Test:');

foreach ($apiHelpers as $key => $value) {
    \Log::info("{$key}: " . (is_array($value) ? json_encode($value) : $value));
}
```

---

Changelog
---------

[](#changelog)

See [CHANGELOG](CHANGELOG.md) for recent changes.

Contributors ✨
--------------

[](#contributors-)

Thanks to these wonderful people for contributing to this project! 💖

   [ ![Omar Al Alwi](https://avatars.githubusercontent.com/u/25439498?v=4)
 **Omar Al Alwi** ](https://github.com/omaralalwi)
 🏆 Creator  Want to contribute? Check out the [contributing guidelines](./CONTRIBUTING.md) and submit a pull request! 🚀

Security
--------

[](#security)

If you discover any security-related issues, please email `omaralwi2010@gmail.com`.

Credits
-------

[](#credits)

- [Omar Alalwi](https://github.com/omaralalwi)

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE.md) for more information.

---

📚 Helpful Open Source Packages &amp; Projects
---------------------------------------------

[](#-helpful-open-source-packages--projects)

### Packages

[](#packages)

- [![lexi translate](https://raw.githubusercontent.com/omaralalwi/lexi-translate/master/public/images/lexi-translate-banner.jpg) Lexi Translate ](https://github.com/omaralalwi/lexi-translate) simplify managing translations for multilingual Eloquent models with power of morph relationships and caching .
- [![Gpdf](https://raw.githubusercontent.com/omaralalwi/Gpdf/master/public/images/gpdf-banner-bg.jpg) Gpdf ](https://github.com/omaralalwi/Gpdf) Open Source HTML to PDF converter for PHP &amp; Laravel Applications, supports Arabic content out-of-the-box and other languages.
- [![laravel Taxify](https://raw.githubusercontent.com/omaralalwi/laravel-taxify/master/public/images/taxify.jpg) **laravel Taxify** ](https://github.com/omaralalwi/laravel-taxify) Laravel Taxify provides a set of helper functions and classes to simplify tax (VAT) calculations within Laravel applications.
- [![laravel Taxify](https://raw.githubusercontent.com/omaralalwi/laravel-api-helpers/master/public/images/laravel-api-helpers.jpg) **laravel API Helpers** ](https://github.com/omaralalwi/laravel-api-helpers) Laravel API Helpers provides a set of helper of helpful helper functions for API Requests ..
- [![laravel Deployer](https://raw.githubusercontent.com/omaralalwi/laravel-deployer/master/public/images/deployer.jpg) **laravel Deployer** ](https://github.com/omaralalwi/laravel-deployer) Streamlined Deployment for Laravel and Node.js apps, with Zero-Downtime and various environments and branches.
- [![laravel Trash Cleaner](https://raw.githubusercontent.com/omaralalwi/laravel-trash-cleaner/master/public/images/laravel-trash-cleaner.jpg) **laravel Trash Cleaner** ](https://github.com/omaralalwi/laravel-trash-cleaner) clean logs and debug files for debugging packages.
- [![laravel Time Craft](https://raw.githubusercontent.com/omaralalwi/laravel-time-craft/master/public/images/laravel-time-craft.jpg) **laravel Time Craft** ](https://github.com/omaralalwi/laravel-time-craft) simple trait and helper functions that allow you, Effortlessly manage date and time queries in Laravel apps.
- [![PHP builders](https://repository-images.githubusercontent.com/917404875/c5fbf4c9-d41f-44c6-afc6-0d66cf7f4c4f) **PHP builders** ](https://github.com/omaralalwi/php-builders) sample php traits to add ability to use builder design patterns with easy in PHP applications.
- [ ![PhpPy - PHP Python](https://avatars.githubusercontent.com/u/25439498?v=4) **PhpPy - PHP Python** ](https://github.com/omaralalwi/php-py) Interact with python in PHP applications.
- [![Laravel Py - Laravel Python](https://avatars.githubusercontent.com/u/25439498?v=4) **Laravel Py - Laravel Python** ](https://github.com/omaralalwi/laravel-py) interact with python in Laravel applications.
- [![Deepseek PHP client](https://avatars.githubusercontent.com/u/193405629?s=200&v=4) **deepseek PHP client** ](https://github.com/deepseek-php/deepseek-php-client) robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities .
- [![deepseek laravel](https://github.com/deepseek-php/deepseek-laravel/raw/master/public/images/laravel%20deepseek%20ai%20banner.jpg?raw=true) **deepseek laravel** ](https://github.com/deepseek-php/deepseek-laravel) Laravel wrapper for Deepseek PHP client to seamless deepseek AI API integration with Laravel applications.
- [![Qwen PHP client](https://avatars.githubusercontent.com/u/197095442?s=200&v=4) **Qwen PHP client** ](https://github.com/qwen-php/qwen-php-client) robust and community-driven PHP client library for seamless integration with the Qwen API .
- [![qwen laravel](https://github.com/qwen-php/qwen-laravel/raw/master/public/images/laravel%20qwen%20ai%20banner.jpg?raw=true) **Laravel qwen** ](https://github.com/qwen-php/qwen-laravel) wrapper for qwen PHP client to seamless Alibaba qwen AI API integration with Laravel applications..

### Dashboards

[](#dashboards)

- [![Laravel Startkit](https://raw.githubusercontent.com/omaralalwi/laravel-startkit/master/public/screenshots/backend-rtl.png) **Laravel Startkit** ](https://github.com/omaralalwi/laravel-startkit) Laravel Admin Dashboard, Admin Template with Frontend Template, for scalable Laravel projects.
- [![Kunafa Dashboard Vue](https://github.com/kunafaPlus/kunafa-dashboard-vue/raw/master/public/screenshots/Home-LTR.png) **Kunafa Dashboard Vue** ](https://github.com/kunafaPlus/kunafa-dashboard-vue) A feature-rich Vue.js 3 dashboard template with multi-language support and full RTL/LTR bidirectional layout capabilities.

### References

[](#references)

- [![Clean Code Summary](https://avatars.githubusercontent.com/u/25439498?v=4) **Clean Code Summary** ](https://github.com/omaralalwi/clean-code-summary) summarize and notes for books and practices about clean code.
- [![SOLID Principles Summary](https://avatars.githubusercontent.com/u/25439498?v=4) **SOLID Principles Summary** ](https://github.com/omaralalwi/solid-principles-summary) summarize and notes for books about SOLID Principles.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance46

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 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 ~0 days

Total

4

Last Release

413d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/92882431481b621f6509ff259dd600e327c27fc77adcba4fcc7177659059c9a8?d=identicon)[omaralalwi](/maintainers/omaralalwi)

---

Top Contributors

[![omaralalwi](https://avatars.githubusercontent.com/u/25439498?v=4)](https://github.com/omaralalwi "omaralalwi (12 commits)")

---

Tags

api-authentication-kitapi-development-boilerplateapi-middleware-packageapi-response-formatterapi-security-helpersapi-version-middlewareapi-versioning-toolsbearer-token-managerclient-ip-detectionhttp-header-utilitieslaravel-api-ecosystemlaravel-api-productivitylaravel-api-utilitieslaravel-developer-toolslaravel-request-parsermultilingual-api-supportphp-api-essentialsrest-api-helpersrestful-api-foundationversioned-api-managerapilaravellocalizationinternationalizationi18nlaravel-packageversioningREST APIRESTful APIcontent negotiationapi versioningdeveloper-toolssecurity-headersapi-toolsapi authenticationlaravel-developersemantic versioningapi-securityclient ipLaravel Utilitiesphp-packageapi-responsejson-responseapi developmentbearer tokenlaravel-developmenthttp-requestslaravel-api-helpersrequest-helpersrequest-handlingbearer-authenticationip-detectionapi-middlewareheader-parsingapi-user-management

### Embed Badge

![Health badge](/badges/omaralalwi-laravel-api-helpers/health.svg)

```
[![Health](https://phpackages.com/badges/omaralalwi-laravel-api-helpers/health.svg)](https://phpackages.com/packages/omaralalwi-laravel-api-helpers)
```

###  Alternatives

[joisarjignesh/bigbluebutton

BigBlueButton Server API Library for Laravel

162145.5k1](/packages/joisarjignesh-bigbluebutton)[shahghasiadil/laravel-api-versioning

Elegant attribute-based API versioning solution for Laravel applications with built-in deprecation management and version inheritance

2913.6k](/packages/shahghasiadil-laravel-api-versioning)[richan-fongdasen/laravel-i18n

Simple route and eloquent localization / translation in Laravel

1296.6k](/packages/richan-fongdasen-laravel-i18n)[jayesh/laravel-gemini-translator

An interactive command to extract and generate Laravel translations using Gemini AI.

691.7k1](/packages/jayesh-laravel-gemini-translator)

PHPackages © 2026

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