PHPackages                             ssdev/laravel-api-contracts - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. ssdev/laravel-api-contracts

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

ssdev/laravel-api-contracts
===========================

API response contract snapshot testing for Laravel — detects breaking changes before they reach production.

v1.0.0(today)03↑2900%MITPHPPHP ^8.2

Since Jul 1Pushed todayCompare

[ Source](https://github.com/SeadSilajdzic/ssdev-laravel-api-contracts)[ Packagist](https://packagist.org/packages/ssdev/laravel-api-contracts)[ RSS](/packages/ssdev-laravel-api-contracts/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (2)Used By (0)

ssdev/laravel-api-contracts
===========================

[](#ssdevlaravel-api-contracts)

API response contract snapshot testing for Laravel — catch breaking changes before they hit production.

---

How it works
------------

[](#how-it-works)

1. You write contract tests that hit your API endpoints and call `assertMatchesApiContract()`
2. On first run, the response shape is saved as a JSON snapshot (committed to git)
3. On every subsequent `git push`, the hook re-runs those tests and compares against the snapshots
4. If a field was removed or a type changed, the push is **blocked** — you see exactly what broke
5. New fields (additive changes) are reported but never block a push

Snapshots are plain JSON files committed alongside your code. Any contract change is a visible git diff.

---

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

[](#installation)

```
composer require ssdev/laravel-api-contracts --dev
```

```
php artisan api:contract:install
```

This sets up:

- `tests/snapshots/api/` — snapshot directory (commit this)
- `.githooks/pre-commit` — warns about routes with no snapshot coverage
- `.githooks/pre-push` — blocks push if existing contracts are broken
- `git config core.hooksPath .githooks`

---

Generating test stubs
---------------------

[](#generating-test-stubs)

Scan your API routes and generate a test file automatically:

```
php artisan api:contract:generate --prefix=api/v1
```

This produces `tests/Feature/ApiContractTest.php` with one test per GET route, ready to fill in:

```
