PHPackages                             nomanur/api-starter-kit - 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. nomanur/api-starter-kit

ActiveLibrary[API Development](/categories/api)

nomanur/api-starter-kit
=======================

A complete Laravel API boilerplate with authentication, transformers, exception handling, and scaffolding commands

v1.0.2(1mo ago)0361MITPHPPHP ^8.2|^8.3|^8.4CI passing

Since Apr 6Pushed 1mo agoCompare

[ Source](https://github.com/nomanur/laravel-api-starter-kit)[ Packagist](https://packagist.org/packages/nomanur/api-starter-kit)[ Docs](https://nomanur.github.io/laravel-api-starter-kit)[ RSS](/packages/nomanur-api-starter-kit/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (9)Dependencies (18)Versions (13)Used By (1)

Laravel API Starter Kit
=======================

[](#laravel-api-starter-kit)

[![Latest Version on Packagist](https://camo.githubusercontent.com/eac980c80a45a7468332a184af729655fa4413da67305630a3256372443559fe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6f6d616e75722f6170692d737461727465722d6b69742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nomanur/api-starter-kit)[![Total Downloads](https://camo.githubusercontent.com/10bca421230881e264fc4e970103d13ac390af49ef57f26cf3c975385dcc36a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6f6d616e75722f6170692d737461727465722d6b69742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nomanur/api-starter-kit)[![PHP Version](https://camo.githubusercontent.com/487804500a039aee09e5d93e41b745b4cd68dcc0fdf801e67d26d30b93f83358/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e302532422d626c75652e737667)](https://camo.githubusercontent.com/487804500a039aee09e5d93e41b745b4cd68dcc0fdf801e67d26d30b93f83358/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e302532422d626c75652e737667)[![Laravel Version](https://camo.githubusercontent.com/d17cc1de7850ccab5822beed01173f8f2b1edf1a3a51dd3d91c6a02ddac4b580/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d392e302532422d7265642e737667)](https://camo.githubusercontent.com/d17cc1de7850ccab5822beed01173f8f2b1edf1a3a51dd3d91c6a02ddac4b580/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d392e302532422d7265642e737667)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE.md)

A complete, production-ready Laravel API boilerplate with authentication, transformers, exception handling, rate limiting, and scaffolding commands. Build APIs faster with a standardized structure and best practices built-in.

For the full documentation, visit .

🚀 Features
----------

[](#-features)

- ✅ **Standardized API Responses** - Consistent JSON response format
- ✅ **Fractal Transformers** - Clean data transformation layer
- ✅ **Exception Handling** - Centralized error handling for all API errors
- ✅ **Rate Limiting** - Built-in API rate limiting middleware
- ✅ **Authentication** - Laravel Sanctum integration ready
- ✅ **Scaffolding Commands** - Generate API resources with one command
- ✅ **Pagination Support** - Built-in pagination with metadata
- ✅ **Caching** - Optional response caching
- ✅ **CORS Support** - Cross-origin request handling
- ✅ **Validation** - Standardized validation error responses
- ✅ **Base Controllers &amp; Models** - Extendable foundation classes
- ✅ **Postman Export** - Export API routes as a Postman Collection with one command

📦 Installation
--------------

[](#-installation)

### Requirements

[](#requirements)

- PHP 8.0 or higher
- Laravel 9.0 or higher
- Composer

### Install via Composer

[](#install-via-composer)

```
composer require nomanur/api-starter-kit
```

### Quick Setup

[](#quick-setup)

Run the installation command to set up everything automatically:

```
php artisan api-starter-kit:install --sanctum --migrations
```

This will:

- Publish the configuration file
- Install Laravel Sanctum for authentication
- Publish database migrations
- Configure exception handling
- Register middleware
- Create helper functions

### Manual Setup

[](#manual-setup)

If you prefer manual setup:

1. Publish the configuration file:

```
php artisan vendor:publish --tag=api-starter-kit-config
```

2. Add the service provider to `config/app.php` (if not auto-discovered):

```
'providers' => [
    // ...
    LaravelApi\StarterKit\ApiStarterKitServiceProvider::class,
],
```

3. Add the facade alias to `config/app.php`:

```
'aliases' => [
    // ...
    'ApiBoilerplate' => LaravelApi\StarterKit\ApiBoilerplateFacade::class,
],
```

4. Register middleware in `bootstrap/app.php`:

First import the namespaces at the top of your `bootstrap/app.php` file:

```
use LaravelApi\StarterKit\Http\Middleware\ApiAuthenticate;
use LaravelApi\StarterKit\Http\Middleware\ApiCors;
use LaravelApi\StarterKit\Http\Middleware\ApiRateLimit;
```

Then register them inside the `withMiddleware` configuration block:

```
->withMiddleware(function (Middleware $middleware) {
    $middleware->alias([
        'api.auth' => ApiAuthenticate::class,
        'api.rate_limit' => ApiRateLimit::class,
        'api.cors' => ApiCors::class,
    ]);
})
```

📖 Usage
-------

[](#-usage)

### Creating Your First API Resource

[](#creating-your-first-api-resource)

The easiest way to create a complete API resource is using the artisan command:

```
php artisan make:api-resource Post
```

This will create:

- Model: `app/Models/Post.php`
- Controller: `app/Http/Controllers/Api/PostsController.php`
- Transformer: `app/Transformers/PostTransformer.php`
- Routes: Added to `routes/api.php`

You can also specify custom names:

```
php artisan make:api-resource Post --model=Article --controller=ArticlesController --transformer=ArticleTransformer
```

To create a migration along with the API resource:

```
php artisan make:api-resource Post --migration
```

This will also create a migration file in `database/migrations/` with a basic table structure (id and timestamps).

### API Response Format

[](#api-response-format)

All API responses follow a standardized format:

**Success Response:**

```
{
    "data": {
        "id": 1,
        "title": "My Post",
        "content": "Post content here",
        "created_at": "2024-01-01T00:00:00+00:00"
    },
    "message": "Post retrieved successfully"
}
```

**Error Response:**

```
{
    "error": "Validation failed",
    "errors": {
        "title": ["The title field is required."],
        "content": ["The content field must be at least 10 characters."]
    }
}
```

**Paginated Response:**

```
{
    "data": [...],
    "message": "Posts retrieved successfully",
    "meta": {
        "current_page": 1,
        "last_page": 5,
        "per_page": 15,
        "total": 75,
        "from": 1,
        "to": 15
    },
    "links": {
        "self": "http://example.com/api/v1/posts?page=1",
        "first": "http://example.com/api/v1/posts?page=1",
        "last": "http://example.com/api/v1/posts?page=5",
        "next": "http://example.com/api/v1/posts?page=2",
        "prev": null
    }
}
```

### Using the Base Controller

[](#using-the-base-controller)

Extend the `ApiController` in your controllers to get all the helper methods:

```
