PHPackages                             sanjokdangol/apicall - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. sanjokdangol/apicall

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

sanjokdangol/apicall
====================

Internal API Call Service for Laravel - Make authenticated API requests within your application kernel

v0.1.0(5mo ago)214[1 issues](https://github.com/sanjok1988/apicall/issues)MITPHPPHP ^8.0|^7.3

Since Jan 25Pushed 4mo agoCompare

[ Source](https://github.com/sanjok1988/apicall)[ Packagist](https://packagist.org/packages/sanjokdangol/apicall)[ RSS](/packages/sanjokdangol-apicall/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

ApiCall - Laravel Internal API Service
======================================

[](#apicall---laravel-internal-api-service)

[![Latest Version on Packagist](https://camo.githubusercontent.com/055a66acba1bed0558870c6c765b94f269829c1bf2b860e1439492f7e661c056/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616e6a6f6b64616e676f6c2f61706963616c6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sanjokdangol/apicall)[![License](https://camo.githubusercontent.com/2db63debb1c216d3cdb9bcc38b109bdb7f95b042c200f298bfcf22ee56141f47/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73616e6a6f6b64616e676f6c2f61706963616c6c2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/55f86c14f0566b86a3cb91f30074de05134c921de6480eeb8fabc63de1b5de6b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73616e6a6f6b64616e676f6c2f61706963616c6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sanjokdangol/apicall)

Internal API call service for Laravel applications. Make authenticated API requests within your application kernel without external HTTP overhead.

Features
--------

[](#features)

- 🚀 **In-Process Requests** - No external HTTP calls
- 🔐 **User Authentication** - Authenticate as any user
- 🎯 **Fluent API** - Beautiful, chainable interface
- 🧪 **Testing Ready** - Like `TestCase::actingAs()`
- 📝 **Clean Response** - Multiple response formats
- 🐛 **Debugging** - Built-in debugging utilities
- ⚡ **Queue-Ready** - Perfect for jobs and commands
- 🔒 **Token-Based** - Support for API tokens and scopes

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

[](#installation)

### Step 1: Add Repository (For Development)

[](#step-1-add-repository-for-development)

In your project's `composer.json`, add the path repository:

```
"repositories": [
    {
        "type": "path",
        "url": "packages/sanjokdangol/apicall"
    }
]
```

### Step 2: Require the Package

[](#step-2-require-the-package)

```
composer require --dev sanjokdangol/apicall
```

> **Note:** This package is meant for development and testing environments. It's added to `require-dev`.

### Step 3: Auto-Discovery

[](#step-3-auto-discovery)

Laravel will auto-discover the service provider. To verify:

```
php artisan package:discover --ansi
```

### Step 4: (Optional) Publish Configuration

[](#step-4-optional-publish-configuration)

```
php artisan vendor:publish --provider="Sanjokdangol\ApiCall\Providers\ApiCallServiceProvider" --tag="apicall-config"
```

This creates `config/apicall.php` for custom configuration.

Quick Start
-----------

[](#quick-start)

### Basic Usage

[](#basic-usage)

```
use Sanjokdangol\ApiCall\Facades\ApiCall;
use App\Models\User;

$user = User::find(1);

// Simple GET request
$posts = ApiCall::actingAs($user)
    ->clean()
    ->get('/api/posts');

// POST with data
$response = ApiCall::actingAs($user)
    ->post('/api/posts', [
        'title' => 'My Post',
        'body' => 'Content here'
    ]);

// With debugging
$response = ApiCall::actingAs($user)
    ->dd()
    ->put('/api/users/1', ['name' => 'Updated']);
```

### In Controllers

[](#in-controllers)

```
namespace App\Http\Controllers;

use ApiCall;
use Illuminate\Http\Request;

class PostController extends Controller
{
    public function store(Request $request)
    {
        $user = auth()->user();

        $post = ApiCall::actingAs($user)
            ->post('/api/posts', $request->validated());

        return response()->json($post, 201);
    }
}
```

### In Services

[](#in-services)

```
namespace App\Services;

use Sanjokdangol\ApiCall\Facades\ApiCall;

class NotificationService
{
    public function sendNotification($user, $data)
    {
        return ApiCall::actingAs($user)
            ->post('/api/notifications', $data);
    }
}
```

### In Jobs/Commands

[](#in-jobscommands)

```
namespace App\Jobs;

use ApiCall;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;

class SyncUserDataJob implements ShouldQueue
{
    use Queueable;

    protected $user;

    public function __construct($user)
    {
        $this->user = $user;
    }

    public function handle()
    {
        $data = ApiCall::actingAs($this->user)
            ->clean()
            ->get('/api/user-data');

        // Process data...
    }
}
```

### In Tests

[](#in-tests)

```
namespace Tests\Feature;

use Tests\TestCase;
use ApiCall;
use App\Models\User;

class PostApiTest extends TestCase
{
    public function test_user_can_create_post()
    {
        $user = User::factory()->create();

        $response = ApiCall::actingAs($user)
            ->post('/api/posts', [
                'title' => 'Test Post',
                'body' => 'Test content'
            ]);

        $this->assertArrayHasKey('id', $response);
        $this->assertEquals('Test Post', $response['title']);
    }
}
```

API Reference
-------------

[](#api-reference)

### Authentication Methods

[](#authentication-methods)

#### `actingAs(Authenticatable $user, array $scopes = [], string $tokenName = 'ApiCall')`

[](#actingasauthenticatable-user-array-scopes---string-tokenname--apicall)

Authenticate as a specific user for API requests.

```
ApiCall::actingAs($user)->get('/api/posts');
ApiCall::actingAs($user, ['read', 'write'])->post('/api/posts', $data);
```

#### `asUser(Authenticatable $user, array $scopes = [], string $tokenName = 'ApiCall')`

[](#asuserauthenticatable-user-array-scopes---string-tokenname--apicall)

Alias for `actingAs()`.

```
ApiCall::asUser($user)->get('/api/posts');
```

#### `withToken(string $token)`

[](#withtokenstring-token)

Use a specific API token instead of generating one.

```
ApiCall::withToken($token)->get('/api/posts');
```

### HTTP Methods

[](#http-methods)

#### `get(string $url, array $query = [])`

[](#getstring-url-array-query--)

Perform a GET request.

```
$posts = ApiCall::actingAs($user)->get('/api/posts');
$post = ApiCall::actingAs($user)->get('/api/posts/1');
$filtered = ApiCall::actingAs($user)->get('/api/posts', ['status' => 'published']);
```

#### `post(string $url, array $data = [])`

[](#poststring-url-array-data--)

Perform a POST request.

```
$post = ApiCall::actingAs($user)->post('/api/posts', [
    'title' => 'New Post',
    'body' => 'Content'
]);
```

#### `put(string $url, array $data = [])`

[](#putstring-url-array-data--)

Perform a PUT request.

```
$updated = ApiCall::actingAs($user)->put('/api/posts/1', [
    'title' => 'Updated Title'
]);
```

#### `patch(string $url, array $data = [])`

[](#patchstring-url-array-data--)

Perform a PATCH request.

```
$updated = ApiCall::actingAs($user)->patch('/api/posts/1', [
    'status' => 'published'
]);
```

#### `delete(string $url, array $data = [])`

[](#deletestring-url-array-data--)

Perform a DELETE request.

```
$result = ApiCall::actingAs($user)->delete('/api/posts/1');
```

### Response Methods

[](#response-methods)

#### `clean(bool $state = true)`

[](#cleanbool-state--true)

Return only the response data, not the full Response object.

```
$data = ApiCall::actingAs($user)->clean()->get('/api/posts');
// Returns: array or object
```

#### `response(bool $state = true)`

[](#responsebool-state--true)

Return the full Response object.

```
$response = ApiCall::actingAs($user)->response()->get('/api/posts');
// Returns: Illuminate\Http\Response
// Access: $response->getStatusCode(), $response->getContent(), etc.
```

#### `dd(bool $state = true)`

[](#ddbool-state--true)

Debug the request and response, then exit.

```
ApiCall::actingAs($user)->dd()->post('/api/posts', $data);
// Dumps request/response details and stops execution
```

Configuration
-------------

[](#configuration)

### Publishing the Config File

[](#publishing-the-config-file)

```
php artisan vendor:publish --provider="Sanjokdangol\ApiCall\Providers\ApiCallServiceProvider" --tag="apicall-config"
```

### Configuration Options

[](#configuration-options)

```
// config/apicall.php

return [
    // Enable/disable API call logging
    'log' => env('APICALL_LOG', false),

    // Log channel
    'log_channel' => env('APICALL_LOG_CHANNEL', 'single'),

    // Token name for authentication
    'token_name' => env('APICALL_TOKEN_NAME', 'ApiCall'),

    // Default scopes
    'default_scopes' => [],
];
```

Use Cases
---------

[](#use-cases)

### 1. **Internal Service Communication**

[](#1-internal-service-communication)

```
// Without leaving the app, call your own API endpoints
$userData = ApiCall::actingAs($user)->get('/api/users/profile');
```

### 2. **Testing API Endpoints**

[](#2-testing-api-endpoints)

```
// Test as if making HTTP requests, but in-process
$response = ApiCall::actingAs($user)->post('/api/posts', $data);
```

### 3. **Background Jobs**

[](#3-background-jobs)

```
// Execute API calls in queued jobs with proper user context
dispatch(new ProcessUserDataJob($user));

// Inside the job
ApiCall::actingAs($this->user)->post('/api/data/process', $data);
```

### 4. **Cross-Module Communication**

[](#4-cross-module-communication)

```
// Call APIs from other packages/modules
$result = ApiCall::actingAs($user)->get('/api/dashboard/stats');
```

### 5. **Webhooks &amp; Event Handlers**

[](#5-webhooks--event-handlers)

```
// Handle events by making API calls
public function handle(UserCreated $event)
{
    ApiCall::actingAs($event->user)->post('/api/onboarding/start');
}
```

Package Directory Structure
---------------------------

[](#package-directory-structure)

```
packages/sanjokdangol/apicall/
├── src/
│   ├── Facades/
│   │   └── ApiCall.php              # Facade for easy access
│   ├── Providers/
│   │   └── ApiCallServiceProvider.php # Service provider
│   └── Services/
│       └── ApiCall.php              # Core service class
├── config/
│   └── apicall.php                  # Configuration file
├── database/                        # Database files (if needed)
├── resources/                       # Resources (if needed)
├── tests/
│   └── Feature/
│       └── ApiCallTest.php          # Package tests
├── composer.json                    # Package dependencies
├── LICENSE.md                       # MIT License
├── README.md                        # This file
└── .gitignore                       # Git ignore rules

```

Development
-----------

[](#development)

### Project Configuration

[](#project-configuration)

AspectDetails**Package Name**`sanjokdangol/apicall`**Namespace**`Sanjokdangol\ApiCall`**Facade**`ApiCall`**Service Key**`apicall`**Minimum PHP**`7.3` / `8.0+`**Minimum Laravel**`8.12+`**Type**Development Package**License**MIT### Running Tests

[](#running-tests)

```
# From package directory
cd packages/sanjokdangol/apicall

# Run tests
../../../vendor/bin/phpunit

# Or from project root
php artisan test packages/sanjokdangol/apicall/tests
```

### Publishing Documentation

[](#publishing-documentation)

```
php artisan vendor:publish --provider="Sanjokdangol\ApiCall\Providers\ApiCallServiceProvider" --tag="apicall-docs"
```

Troubleshooting
---------------

[](#troubleshooting)

### Package Not Auto-Discovered

[](#package-not-auto-discovered)

```
php artisan package:discover --ansi
composer dump-autoload
php artisan cache:clear
```

### Facade Not Found

[](#facade-not-found)

Ensure the package is installed:

```
composer show sanjokdangol/apicall
```

Manually register in `config/app.php` if needed:

```
'providers' => [
    // ...
    Sanjokdangol\ApiCall\Providers\ApiCallServiceProvider::class,
],

'aliases' => [
    // ...
    'ApiCall' => Sanjokdangol\ApiCall\Facades\ApiCall::class,
],
```

### Class Not Found

[](#class-not-found)

Clear and regenerate autoloader:

```
composer dump-autoload
php artisan tinker
> use Sanjokdangol\ApiCall\Facades\ApiCall;
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This package is open-source software licensed under the [MIT license](LICENSE.md).

Support
-------

[](#support)

For issues, questions, or suggestions, please open an issue on the repository.

---

**Made with ❤️ for Laravel developers**

```

---

## Key Updates Made:

1. ✅ Changed package name from `sanjokDangol/apicall` to `sanjokdangol/apicall`
2. ✅ Updated namespace from `SanjokDangol\ApiCall` to `Sanjokdangol\ApiCall`
3. ✅ Added `require-dev` note explaining development-only package
4. ✅ Added repository configuration instructions
5. ✅ Added comprehensive API reference
6. ✅ Added real-world use cases
7. ✅ Added configuration section
8. ✅ Added troubleshooting guide
9. ✅ Added development tips
10. ✅ Better organization and formatting
11. ✅ More code examples
12. ✅ Added jobs/commands examples

```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance63

Regular maintenance activity

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

160d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/92e7cda10fff7e1e0b3b798017c452a57a5a42ce8250a24be780fa8e16a4c779?d=identicon)[sanjok](/maintainers/sanjok)

---

Top Contributors

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

---

Tags

apilaravelAuthenticationserviceinternal API

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sanjokdangol-apicall/health.svg)

```
[![Health](https://phpackages.com/badges/sanjokdangol-apicall/health.svg)](https://phpackages.com/packages/sanjokdangol-apicall)
```

###  Alternatives

[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6804.7k6](/packages/hasinhayder-tyro)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

84611.1M63](/packages/php-open-source-saver-jwt-auth)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M132](/packages/laravel-pulse)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)

PHPackages © 2026

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