Looking to hire Laravel developers? Try LaraJobs

laravel-kit maintained by net-code

Description
Small, reusable conventions for building Laravel REST APIs: a Clock port, sort direction, paginated-response envelope, an idempotency middleware, ISO country-code rule, and a base context service provider.
Last update
2026/07/15 17:15 (dev-main)
License
Links
Downloads
7

Comments
comments powered by Disqus

net-code/laravel-kit

Small, reusable conventions for building Laravel REST APIs — the framework-level glue that would otherwise be copy-pasted between projects. Extracted from the net-tech portfolio API.

No service provider, no config, no magic: just a handful of classes you reach for directly.

Install

composer require net-code/laravel-kit

What's inside

Class Purpose
NetCode\Kit\Clock / SystemClock Injectable time port + system implementation. Bind Clock to SystemClock (or a fixed clock in tests).
NetCode\Kit\SortDirection asc / desc string enum for list queries.
NetCode\Kit\Http\PaginatedResponse Builds the {meta, links} half of a paginated JSON envelope from the request + page numbers.
NetCode\Kit\Http\Idempotency HTTP idempotency middleware — replays the first successful response for a repeated Idempotency-Key on POST, with a concurrency lock. Cache-store agnostic (the host-provided cache repository); register it under a middleware alias.
NetCode\Kit\Validation\CountryCode Validation rule accepting any ISO 3166-1 alpha-2 country code.
NetCode\Kit\ContextServiceProvider Base service provider with registerBindings() / bootContext() hooks for modular-monolith bounded contexts.

Usage

use NetCode\Kit\Clock;
use NetCode\Kit\SystemClock;

$this->app->bind(Clock::class, SystemClock::class);
use NetCode\Kit\Http\PaginatedResponse;

return response()->json([
    'data' => $rows,
    ...PaginatedResponse::meta($request, $page, $perPage, $total),
]);
use NetCode\Kit\Validation\CountryCode;

$request->validate(['country' => ['required', new CountryCode]]);

Scramble/OpenAPI operation transformers previously shipped here have moved to the dedicated net-code/laravel-scramble package, keeping this kit dependency-light.

License

MIT