PHPackages                             nrikiji/breeze-api - 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. nrikiji/breeze-api

ActiveLibrary[API Development](/categories/api)

nrikiji/breeze-api
==================

0.1.1(4y ago)191.6k4[1 PRs](https://github.com/nrikiji/laravel-breeze-api/pulls)MITPHPPHP ^7.3|^8.0

Since Jun 11Pushed 2y ago1 watchersCompare

[ Source](https://github.com/nrikiji/laravel-breeze-api)[ Packagist](https://packagist.org/packages/nrikiji/breeze-api)[ RSS](/packages/nrikiji-breeze-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (6)Used By (0)

laravel-breeze-api
==================

[](#laravel-breeze-api)

This is a package for easy implementation of API endpoints based on [Breeze](https://github.com/laravel/breeze).

Since it provides only API, it does not have any files (blade, javascript, css) related to Breeze's View.

It is also used in conjunction with [Sanctum](https://github.com/laravel/sanctum) to implement authentication by session and authentication by token in SPA.

setup
-----

[](#setup)

```
$ laravel new my-app

$ cd my-app

$ composer require nrikiji/breeze-api

$ php artisan breeze-api:install

```

Next, install sanctum

```
$ composer require laravel/sanctum

$ php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"

$ php artisan migrate

```

Use the HasApiTokens trate in the User model to use API tokens

app/Models/User.php

```
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;
}

```

Add middleware to the API to use Sanctum and sessions

app/Http/Kernel.php

```
protected $middlewareGroups = [
    'api' => [
        'throttle:api',
        \Illuminate\Routing\Middleware\SubstituteBindings::class,

        # Added the following three items
        \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Session\Middleware\StartSession::class,
    ],
];

```

### If cors is required

[](#if-cors-is-required)

※ example
backend :
frontend :

.env

```
SANCTUM_STATEFUL_DOMAINS=localhost:3000
SESSION_DOMAIN=localhost

```

app/config/cors.php

```
'supports_credentials' => true,

```

### To enable user email authentication

[](#to-enable-user-email-authentication)

Implement the MustVerifyEmail interface

app/Models/User.php

```
use Illuminate\Contracts\Auth\MustVerifyEmail;

class User extends Authenticatable implements MustVerifyEmail
{
  ・・・
}

```

### If you need to send an email

[](#if-you-need-to-send-an-email)

Used for email address verification and password reset functions

Configure the mail server

.env

```
MAIL_MAILER=smtp
MAIL_HOST=smtp.example.com
MAIL_PORT=465
MAIL_USERNAME=mail_username
MAIL_PASSWORD=mail_password
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=no-reply@example.com
MAIL_FROM_NAME="${APP_NAME}"

```

Set the URL for the link that will be included in the confirmation email.

app/Http/Providers/AuthServiceProvider.php

```
// URL for email address verification
VerifyEmail::createUrlUsing(function ($notifiable) {
    $id = $notifiable->getKey();
    $hash = sha1($notifiable->getEmailForVerification());

    ・・・

    // This URL will be inserted as a link in the email, using the id and hash to request the $endpoint
    $parsed = parse_url($endpoint);

    $url = "https://example.com" . $parsed["path"] . "?" . $parsed["query"];

    return $url;
});

// URL for password reset
ResetPassword::createUrlUsing(function ($user, string $token) {
    // This URL will be inserted as a link in the email, and the token will be used to request the API
    return 'https://example.com/reset-password?token=' . $token;
});

```

Usage
-----

[](#usage)

### API Token

[](#api-token)

User Registration

```
$ curl -v -X POST -H 'Accept: application/json' http://localhost:8000/api/register -d 'name=hoge' -d 'email=hoge@example.com' -d 'password=password' -d 'password_confirmation=password'
{"token":"xxxxxxxxxx"}

```

Resend URL for user email address verification

```
curl -v -X POST -H 'Accept: application/json' -H 'Authorization: Bearer xxxxxxxxxx' "http://localhost:8000/api/email/verification-notification"

```

User email address verification
\*The endpoint is determined from the URL in the body of the email.

```
$ curl -v -X GET -H 'Accept: application/json' -H 'Authorization: Bearer xxxxxxxxxx' "http://localhost:8000/api/verify-email/123/yyyyyyyyyy?expires=1623304571&signature=zzzzzzzzzz"

```

Login

```
$ curl -v -X POST -H 'Accept: application/json' http://localhost:8000/api/login -d 'email=hoge@example.com' -d 'password=password'
{"token":"xxxxxxxxxx"}

```

User information

```
$ curl -v -X GET -H 'Accept: application/json' -H 'Authorization: Bearer xxxxxxxxxx' http://localhost:8000/api/user
{"id":1,"name":"hoge","email":"hoge@example.com","email_verified_at":null,"created_at":"2021-06-10T02:34:45.000000Z","updated_at":"2021-06-10T02:34:45.000000Z"}

```

Logout

```
$ curl -v -X POST -H 'Accept: application/json' -H 'Authorization: Bearer xxxxxxxxxx' http://localhost:8000/api/logout

```

Password reset

```
$ curl -v -X POST -H 'Accept: application/json' http://localhost:8000/api/forgot-password -d "email=hoge@example.com"

```

Password reset2

- Get the token from the body of the confirmation email.

```
$ curl -v -X POST -H 'Accept: application/json' http://localhost:8000/api/reset-password -d "email=hoge@example.com" -d "password=password" -d "password_confirmation=password" -d "token=xxxxxxxxxx"

```

### SPA

[](#spa)

axios example
for cors, set withCredentials=true

```
axios.defaults.withCredentials = true;

```

User Registration

```
await axios.get(API_URL + 'sanctum/csrf-cookie');
await axios.post(API_URL + 'api/register',{
  name: "hoge",
  email: "hoge@example.com",
  password: "password",
  password_confirmation: "password",
});

```

Resend URL for user email address verification

```
await axios.post(API_URL + 'email/verification-notification');

```

User email address verification
\*The endpoint is determined from the URL in the body of the email.

```
const path = "api/verify-email/123/xxxxxxxxxx?expires=1623206775&signature=yyyyyyyyyy";
await axios.get(API_URL + path);

```

Login

```
await axios.get(API_URL + 'sanctum/csrf-cookie');
await axios.post(API_URL + 'api/login', {　email: "hoge@example.com",　password: "password" });

```

User information

```
const user = await axios.get(API_URL + 'api/user');
console.log(user); // => {id: 1, name: "hoge", email: "hoge@example.com", email_verified_at: null,…}

```

Logout

```
await axios.post(API_URL + 'api/logout');

```

Password reset

```
await axios.post(API_URL + 'api/forgot-password', { email: "hoge@example.com" });

```

Password reset2

- Get the token from the body of the confirmation email.

```
await axios.post(API_URL + 'api/reset-password', {
  email: "hoge@example.com",
  password: "password",
  password_confirmation: "password",
  token: "xxxxxxxxxx",
});

```

trouble shooting
----------------

[](#trouble-shooting)

### API responses become HTML (text) instead of JSON.

[](#api-responses-become-html-text-instead-of-json)

Add "Accept: application/json" to the HTTP request header. Laravel will try to make the response JSON when using Ajax requests or when this header is specified. Laravel will try to make the response JSON when requesting via Ajax or when this header is specified.

However, we have prepared HandleAuthApiRequests middleware for cases where it is not possible to add this header. Please use it as appropriate. This can be enabled by adding it to app/Http/Kernel.php.

Link
----

[](#link)

-
-

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.9% 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 ~43 days

Total

5

Last Release

1619d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/687032c3a2b42cacc1a6ef8b3eb7cf29ad8b3b9faef0f98d790ba7780843fe23?d=identicon)[nrikiji](/maintainers/nrikiji)

---

Top Contributors

[![nrikiji](https://avatars.githubusercontent.com/u/4780752?v=4)](https://github.com/nrikiji "nrikiji (10 commits)")[![charliemerland](https://avatars.githubusercontent.com/u/87287781?v=4)](https://github.com/charliemerland "charliemerland (1 commits)")

---

Tags

apibreezelaravelphp

### Embed Badge

![Health badge](/badges/nrikiji-breeze-api/health.svg)

```
[![Health](https://phpackages.com/badges/nrikiji-breeze-api/health.svg)](https://phpackages.com/packages/nrikiji-breeze-api)
```

###  Alternatives

[laravel/ui

Laravel UI utilities and presets.

2.7k134.9M597](/packages/laravel-ui)[laravel/breeze

Minimal Laravel authentication scaffolding with Blade and Tailwind.

3.0k31.3M145](/packages/laravel-breeze)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)

PHPackages © 2026

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