Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

laravel-api

/laravel-api

Pomaga tworzyć endpointy API w Laravel, przekształcać odpowiedzi przez API Resources oraz obsługiwać uwierzytelnianie, limity żądań i wersjonowanie API.

Repozytorium
agents ↗
Licencja
MIT
Ostatnia zmiana repozytorium
12.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
20
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 12.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pomaga tworzyć endpointy API w Laravel, przekształcać odpowiedzi przez API Resources oraz obsługiwać uwierzytelnianie, limity żądań i wersjonowanie API.

Oryginalny opis (EN)

Use when creating API endpoints, transforming responses with API Resources, or handling API authentication, rate limiting, or versioning.

Jak działa

  1. Agent Workflow (MANDATORY)
  2. Overview
  3. Critical Rules
  4. Reference Guide
  5. Quick Reference
  6. Feature Matrix
  7. Laravel 13 Notes
  8. Best Practices
Sekcje z nagłówków SKILL.md, w oryginale · 209 linii, 821 słów
Podgląd SKILL.md
---
name: laravel-api
description: Use when creating API endpoints, transforming responses with API Resources, or handling API authentication, rate limiting, or versioning.
versions:
  laravel: "13.0"
  php: "8.3"
user-invocable: true
references: references/routing.md, references/controllers.md, references/middleware.md, references/requests.md, references/responses.md, references/validation.md, references/pagination.md, references/http-client.md, references/rate-limiting.md, references/redirects.md, references/urls.md, references/strings.md
related-skills: laravel-auth, laravel-eloquent, laravel-testing
---

<objective>
Covers building RESTful APIs with Laravel: API Resources for response
transformation, Sanctum authentication, rate limiting, route versioning, Form
Request validation, pagination (offset/cursor), and consuming external APIs
via the HTTP client. For JSON:API-spec-compliant endpoints (sparse fieldsets,
inclusion, links), see laravel-jsonapi instead.
</objective>

# Laravel API Development

## Agent Workflow (MANDATORY)

Before ANY implementation, spawn 3 agents in parallel, one `Agent` call each with a `name`:

1. **fuse-ai-pilot:explore-codebase** - Analyze existing API patterns
2. **fuse-ai-pilot:research-expert** - Verify Laravel API docs via Context7
3. **mcp__context7__query-docs** - Check API Resources and Sanctum patterns

After implementation, run **fuse-ai-pilot:sniper** for validation.

---

## Overview

Build RESTful APIs with Laravel using API Resources for response transformation and Sanctum for authentication.

| Component | Purpose |
|-----------|---------|
| **Controllers** | Handle requests, delegate to services |
| **Form Requests** | Validate input, authorize actions |
| **API Resources** | Transform models to JSON |
| **Middleware** | Auth, rate limiting, CORS |
| **Routes** | Versioned endpoints with groups |
| **Pagination** | Offset/cursor pagination |
| **HTTP Client** | Consume external APIs |

---

## Critical Rules

1. **Always use API Resources** - Never return Eloquent models directly
2. **Versioned routes** - Prefix with `/v1/`, `/v2/`
3. **Validate all input** - Use Form Requests, not inline validation
4. **Rate limiting** - Configure per-route limits
5. **Consistent responses** - Same structure, proper status codes
6. **Use services** - Keep controllers thin
7. **Eager load** - Prevent N+1 with `with()` before pagination

---

## Reference Guide

### Core Concepts

| Topic | Reference | When to consult |
|-------|-----------|-----------------|
| **Routing** | [routing.md](references/routing.md) | Defining versioned API routes |
| **Controllers** | [controllers.md](references/controllers.md) | Controller patterns, resource methods |
| **Middleware** | [middleware.md](references/middleware.md) | Route protection, request filtering |
| **Validation** | [validation.md](references/validation.md) | Form Requests, validation rules |

### Request/Response

| Topic | Reference | When to consult |
|-------|-----------|-----------------|
| **Requests** | [requests.md](references/requests.md) | Accessing input, files, headers |
| **Responses** | [responses.md](references/responses.md) | API Resources, status codes |
| **Pagination** | [pagination.md](references/pagination.md) | Offset/cursor pagination |

### Advanced

| Topic | Reference | When to consult |
|-------|-----------|-----------------|
| **Rate Limiting** | [rate-limiting.md](references/rate-limiting.md) | Throttle configuration |
| **HTTP Client** | [http-client.md](references/http-client.md) | Consuming external APIs |
| **URLs** | [urls.md](references/urls.md) | URL generation, signed URLs |
| **Strings** | [strings.md](references/strings.md) | String helpers, UUIDs, slugs |
| **Redirects** | [redirects.md](references/redirects.md) | Redirect responses |

---

### Templates (Code Examples)

#### Controllers & Routes

| Template | Purpose |
|----------|---------|
| [ApiController.php.md](references/templates/ApiController.php.md) | Complete CRUD controller with service |
| [api-routes.md](references/templates/api-routes.md) | Versioned routes with middleware |
| [routing-examples.md](references/templates/routing-examples.md) | Detailed routing patterns |

#### Validation & Resources

| Template | Purpose |
|----------|---------|
| [FormRequest.php.md](references/templates/FormRequest.php.md) | Store/Update Form Requests |
| [validation-rules.md](references/templates/validation-rules.md) | All validation rules reference |
| [ApiResource.php.md](references/templates/ApiResource.php.md) | Resource with relationships |

#### External APIs

| Template | Purpose |
|----------|---------|
| [HttpClientService.php.md](references/templates/HttpClientService.php.md) | Reusable HTTP client service |

---

## Quick Reference

### Resource Response

```php
return PostResource::collection($posts);
return PostResource::make($post);
```

### Status Codes

```php
return PostResource::make($post)->response()->setStatusCode(201);
return response()->json(null, 204);
```

### Form Request

```php
public function store(StorePostRequest $request): JsonResponse
{
    $post = $this->service->create($request->validated());
    return PostResource::make($post)->response()->setStatusCode(201);
}
```

### Rate Limiting

```php
Route::middleware('throttle:60,1')->group(fn () => ...);
```

### Versioned Routes

```php
Route::prefix('v1')->group(function () {
    Route::apiResource('posts', PostController::class);
});
```

### Pagination

```php
return PostResource::collection(Post::paginate(15));
```

---

## Feature Matrix

| Feature | Status | Reference |
|---------|--------|-----------|
| RESTful Controllers | ✅ | controllers.md |
| API Resources | ✅ | responses.md |
| Form Request Validation | ✅ | validation.md |
| Route Versioning | ✅ | routing.md |
| Route Model Binding | ✅ | routing.md |
| Middleware | ✅ | middleware.md |
| Rate Limiting | ✅ | rate-limiting.md |
| Pagination | ✅ | pagination.md |
| Cursor Pagination | ✅ | pagination.md |
| HTTP Client | ✅ | http-client.md |
| Signed URLs | ✅ | urls.md |
| JSON Responses | ✅ | responses.md |

---

## Laravel 13 Notes

### Attributes for API Resources
Laravel 13 introduces `#[Collects]` and `#[PreserveKeys]` to configure ResourceCollections via PHP attributes.

```php
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Http\Resources\Attributes\Collects;
use Illuminate\Http\Resources\Attributes\PreserveKeys;

#[Collects(PostResource::class)]
#[PreserveKeys]
final class PostCollection extends ResourceCollection {}
```

### JSON:API compliance
For JSON:API APIs (sparse fieldsets, includes, links), see [[laravel-jsonapi]], which covers `?include=`, `?fields[type]=`, and spec-compliant pagination.

## Best Practices

### DO
- Use API Resources (`JsonResource`) for every public JSON response
- Version via URL (`/api/v1`) rather than via header (readable, cacheable)
- Rate-limit per user AND per IP (`throttle:60,1` + custom limiter)
- Document via OpenAPI/Scribe before coding the endpoint
- Prefer `cursor()` pagination for large lists (stable, performant)

### DON'T
- Return an Eloquent Model directly (leaks sensitive columns)
- Mix up HTTP statuses (always 422 for validation, 401 vs 403)
- Skip Form Request validation (never validate in the controller)
- Expose auto-increment IDs publicly (prefer UUID/ULID)
- Forget the `PreventRequestForgery` exemption for external webhooks
Pliki w paczce (20)
  • SKILL.md 7 KB
  • references/controllers.md 4 KB
  • references/http-client.md 4 KB
  • references/middleware.md 3 KB
  • references/pagination.md 3 KB
  • references/rate-limiting.md 5 KB
  • references/redirects.md 5 KB
  • references/requests.md 4 KB
  • references/responses.md 4 KB
  • references/routing.md 4 KB
  • references/strings.md 3 KB
  • references/urls.md 3 KB
  • references/validation.md 4 KB
  • references/templates/ApiController.php.md 3 KB
  • references/templates/ApiResource.php.md 6 KB
  • references/templates/FormRequest.php.md 5 KB
  • references/templates/HttpClientService.php.md 4 KB
  • references/templates/api-routes.md 2 KB
  • references/templates/routing-examples.md 6 KB
  • references/templates/validation-rules.md 5 KB

Wersje

RepozytoriumWynikLicencja
Ta strona · fusengine/agents100MIT
HoangNguyen0403/agent-skills-standard100MIT

Migawka bazy z 28.10.2026 · wersja paczki 1592e9f9f9ff (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100laravel-auth
    Pomaga wdrożyć uwierzytelnianie użytkowników, tokeny API, logowanie społecznościowe i autoryzację w Laravel 13.
  • 95api-design
    Opisuje wzorce projektowania REST API: nazwy zasobów, kody statusu, paginację, filtrowanie, odpowiedzi błędów, wersjonowanie i rate limiting dla API produkcyjnych.
  • 95api-design
    Opisuje wzorce projektowania REST API: nazwy zasobów, kody statusu, paginację, filtrowanie, odpowiedzi błędów, wersjonowanie i rate limiting dla API produkcyjnych.
  • 100rest-api-best-practices
    Doradza w projektowaniu i przeglądzie REST API: metody i kody HTTP, nazewnictwo URL, błędy, paginacja, wersjonowanie, uwierzytelnianie i rate limiting.
  • 100api-design
    Pomaga projektować, implementować i recenzować API HTTP: endpointy, kształt żądań i odpowiedzi, błędy, paginacja, wersjonowanie i autoryzacja.
  • 100laravel-jsonapi
    Buduje w Laravel 13 endpointy zgodne ze specyfikacją JSON:API z użyciem natywnej klasy bazowej JsonApiResource.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.