Skip to main content

28 docs tagged with "api"

View all tags

Authentication — token authentication with Sanctum

Chapter 11 of the Laravel API Development Guide. Builds sign-up, login, and logout with Sanctum and protects routes with token authentication. It covers moving guest orders onto user accounts, token abilities and expiration, and creating an authenticated state in tests.

Authorization — deciding who can do what with Gates and Policies

Chapter 12 of the Laravel API Development Guide. While building the order listing and detail endpoints, it implements per-model authorization with a Policy. It covers why a Policy does not take effect on a listing, choosing between 403 and 404, and detecting authorization gaps with tests.

Backend

A hub for the domain that collects notes on server-side development, including API design, authentication, and databases. It covers business logic design, data persistence, and building APIs.

Caching — how much correctness you trade for speed

Chapter 18 of the Laravel API Development Guide. Covers deciding what may be cached, Cache::remember and driver choice, key design, TTLs and explicit invalidation, stampede protection (Cache::flexible and Cache::lock), Laravel 13's Cache::touch, and writing tests that use the cache.

Error design — translating exceptions into HTTP responses

Chapter 9 of the Laravel API Development Guide. Settles the shape of error responses, creates custom exception classes, and makes withExceptions in bootstrap/app.php the one and only conversion point. It also covers what goes to the log and what is never shown to the client.

Error handling — normal, near-normal, and abnormal paths

This chapter classifies the results of a process into normal, near-normal, and abnormal paths and explains handling for each. It covers the criterion separating expected from unexpected failures, when to use exceptions vs. return values, where to catch, and what to tell users and logs.

Events and notifications — decoupling everything after order confirmation

Chapter 15 of the Laravel API Development Guide. Solves the problem of processing piling up in a service class with events and listeners. It covers listener auto-discovery, Notification classes and Mailables, measuring the cost of synchronous sending, and testing with Notification::fake versus Mail::fake.

File storage — product images and receipt PDFs

Chapter 19 of the Laravel API Development Guide. Covers the disk abstraction and choosing between local and public, validating and storing uploads, protection with Sanctum abilities, serving private files and signed URLs, generating PDFs in a job, keeping files and records consistent, and testing with Storage::fake.

HTTP — methods, statuses, and headers

This chapter starts from the structure of HTTP requests and responses and then covers the nine standard methods with their safety and idempotency, and the classification of status codes. It covers how to choose between PUT, PATCH, and POST by what the body means, explains that methods appear only on the request line, and why UPDATE and REMOVE are not the ones to use.

Introduction — what we build, and what we leave out

Chapter 1 of the Laravel API Development Guide. Shows three places where an order API written straight from a tutorial breaks in production, and sets out this series' scope, its subject, and how it fits with the existing guides.

Laravel API Development Guide

A 22-chapter guide to using Laravel as an API backend. It works through routing, Eloquent, and validation basics, then authentication and authorization (Sanctum, Policy), caching, queues, the task scheduler, file storage, and production operations, all built around an e-commerce order system. Blade and other frontend features are out of scope.

Logging, monitoring, and deployment — being able to trace what happened

Chapter 21 of the Laravel API Development Guide. Covers channels and stacks in config/logging.php, propagating a request ID with Context, routing expected and unexpected errors, recording 404s and 429s, masking sensitive data with a Monolog processor, structured logs, the order of deployment steps, and health-checking the scheduler.

Modeling the subject and seeding data — tables, models, and seeders

Chapter 3 of the Laravel API Development Guide. Creates the products, stock, orders, and order lines tables with migrations, maps Eloquent models to enums, and prepares development data with factories and seeders. It also settles how amounts are typed and how mass assignment is handled.

Queue basics — moving heavy work out of the request

Chapter 16 of the Laravel API Development Guide. Makes a listener asynchronous with ShouldQueue and runs a worker with queue:work. It also covers Job classes and dispatch, choosing a driver, SerializesModels, afterCommit for not dispatching inside a transaction, Queue::route, and testing with Queue::fake.

Queues in production — idempotency, retries, and failed_jobs

Chapter 17 of the Laravel API Development Guide. Covers writing idempotently on the premise that a job runs twice, retry design with Tries and Backoff, failed_jobs and queue:retry, ShouldBeUnique and WithoutOverlapping, and keeping workers alive with Supervisor plus queue:restart.

Retries and idempotency — telling safe retries apart

This chapter classifies failures into determined, indeterminate, and overload, and derives when a retry is safe from idempotency. It covers why exponential backoff needs jitter, why the ceiling is two values (attempt count and total elapsed time), and what an idempotency key guarantees.

Routing design and your first endpoint

Chapter 4 of the Laravel API Development Guide. Builds the API skeleton with install:api, groups routes with apiResource, and turns IDs into models with route model binding. It also covers URL design, versioning, and choosing status codes.

Summary — a pre-release checklist

The final chapter of the Laravel API Development Guide. It gathers what the 21 chapters settled into one list to run through before shipping to production, with checklists by area — configuration, database, input and output, authorization, asynchronous work, logging, and deployment — plus an index of which chapter decided what.

Testing — pinning down the API's contract with Pest

Chapter 10 of the Laravel API Development Guide. Introduces how to write Pest and adds Feature tests to the API built so far. It covers why failure paths matter as much as the happy path, preparing test data, and the testing pattern the rest of the series follows.

The listing API — pagination, filters, and N+1

Chapter 8 of the Laravel API Development Guide. Using the product listing API, it covers choosing between the three kinds of pagination, safely accepting filters and sorting, observing the N+1 problem and solving it with eager loading, and detecting it mechanically.

The request lifecycle and the skeleton of Laravel 13

Chapter 2 of the Laravel API Development Guide. Follows the path one request takes from public/index.php to the controller, and shows where bootstrap/app.php, the service container, service providers, and the config files plug into that path.

The task scheduler — collapsing scheduled work into a single cron line

Chapter 20 of the Laravel API Development Guide. Covers defining schedules in routes/console.php, why the cron entry stays one line, pruning expired tokens, negative stock, and orphaned files, auto-cancelling unpaid orders and deciding what "unpaid" means, withoutOverlapping and onOneServer, and tests with travelTo plus wiring tests.

Transactions and concurrency — closing double-allocated stock

Chapter 14 of the Laravel API Development Guide. Covers atomicity with DB::transaction, row locks with lockForUpdate, conditional UPDATEs, and retrying on deadlock. It also covers preventing duplicate orders with an Idempotency-Key and a unique constraint.

Validating input — fixing the boundary with a Form Request

Chapter 5 of the Laravel API Development Guide. Using the order creation API, it moves validation written inline in the controller into a Form Request. It covers validating arrays and nested data, hooking in before and after validation, customizing messages, and the line between shape checks and business rules.

Where business logic belongs — service classes and the service container

Chapter 6 of the Laravel API Development Guide. Diagnoses the controller for the order creation API built in the previous chapter and extracts it into a service class. It covers what goes in an Eloquent model and what does not, automatic dependency resolution by the service container, and binding interfaces.