Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Effortless API Documentation with Scribe

Avatar for SAW SAW
May 26, 2026

Effortless API Documentation with Scribe

A presentation slide of Laravel Live Japan 2026

Avatar for SAW

SAW

May 26, 2026

More Decks by SAW

Other Decks in Programming

Transcript

  1. What Is Scribe? A library to help generate API documentation

    Human-friendly and interactive Web UI OpenAPI spec and Postman collection Laravel-specific features 7 Laravel Live Japan 2026
  2. Installation 1. Install the Scribe package with Composer 2. Publish

    the Scribe config file Prerequisite PHP 8.1 or higher Laravel 9 or higher composer require knuckleswtf/scribe php artisan vendor:publish --tag=scribe-config 8 Laravel Live Japan 2026
  3. The Simplest Usage 1. Define API routes in routes/api.php .

    2. Run the document generation command php artisan scribe:generate . Access /docs after the command finishes. Route::get('/sample', [SampleController::class, 'sample']); Laravel Live Japan 2026 9
  4. Add Request Body Information 1. Add Laravel’s request validation feature.

    2. Run the document generation command php artisan scribe:generate . $validated = $request->validate([ 'message' => ['required'], ]); Laravel Live Japan 2026 11
  5. Add Response Examples 1. Adjust config/scribe.php to generate example responses

    automatically. add items to the only parameter to specify which endpoints Scribe should call remove the only parameter to allow Scribe to call all endpoints 2. Run the document generation command php artisan scribe:generate . 'responses' => configureStrategy( Defaults::RESPONSES_STRATEGIES, Strategies\Responses\ResponseCalls::withSettings( only: ['GET *'], config: ['app.debug' => false], ), ), Laravel Live Japan 2026 12
  6. Add Response Examples 1. Adjust config/scribe.php to generate example responses

    automatically. add items to the only parameter to specify which endpoints Scribe should call remove the only parameter to allow Scribe to call all endpoints 2. Run the document generation command php artisan scribe:generate . only: ['GET *'], 'responses' => configureStrategy( Defaults::RESPONSES_STRATEGIES, Strategies\Responses\ResponseCalls::withSettings( config: ['app.debug' => false], ), ), Laravel Live Japan 2026 12
  7. Add Response Examples 1. Adjust config/scribe.php to generate example responses

    automatically. add items to the only parameter to specify which endpoints Scribe should call remove the only parameter to allow Scribe to call all endpoints 2. Run the document generation command php artisan scribe:generate . only: ['GET *', 'POST *'], 'responses' => configureStrategy( Defaults::RESPONSES_STRATEGIES, Strategies\Responses\ResponseCalls::withSettings( config: ['app.debug' => false], ), ), Laravel Live Japan 2026 12
  8. Add Response Examples 1. Adjust config/scribe.php to generate example responses

    automatically. add items to the only parameter to specify which endpoints Scribe should call remove the only parameter to allow Scribe to call all endpoints 2. Run the document generation command php artisan scribe:generate . 'responses' => configureStrategy( Defaults::RESPONSES_STRATEGIES, Strategies\Responses\ResponseCalls::withSettings( config: ['app.debug' => false], ), ), Laravel Live Japan 2026 12
  9. Other Powerful Scribe Features #[Endpoint()] : Add an endpoint description

    #[UrlParam()] : Add details for a URL parameter #[QueryParam()] , #[BodyParam()] : Add query and body parameter details #[ResponseFromApiResource()] : Generate a response example from ApiResource and more… public function find(int $id): SampleMessageResource { $message = SampleMessage::findOrFail($id); return new SampleMessageResource($message); } Laravel Live Japan 2026 14
  10. Other Powerful Scribe Features #[Endpoint()] : Add an endpoint description

    #[UrlParam()] : Add details for a URL parameter #[QueryParam()] , #[BodyParam()] : Add query and body parameter details #[ResponseFromApiResource()] : Generate a response example from ApiResource and more… #[Endpoint('Find The Sample Message', 'Return the sample message.')] public function find(int $id): SampleMessageResource { $message = SampleMessage::findOrFail($id); return new SampleMessageResource($message); } Laravel Live Japan 2026 14
  11. Other Powerful Scribe Features #[Endpoint()] : Add an endpoint description

    #[UrlParam()] : Add details for a URL parameter #[QueryParam()] , #[BodyParam()] : Add query and body parameter details #[ResponseFromApiResource()] : Generate a response example from ApiResource and more… #[UrlParam('id', 'integer', 'The ID of the message.')] public function find(int $id): SampleMessageResource #[Endpoint('Find The Sample Message', 'Return the sample message.')] { $message = SampleMessage::findOrFail($id); return new SampleMessageResource($message); } Laravel Live Japan 2026 14
  12. Other Powerful Scribe Features #[Endpoint()] : Add an endpoint description

    #[UrlParam()] : Add details for a URL parameter #[QueryParam()] , #[BodyParam()] : Add query and body parameter details #[ResponseFromApiResource()] : Generate a response example from ApiResource and more… #[ResponseFromApiResource(SampleMessageResource::class, SampleMessage::class)] return new SampleMessageResource($message); #[Endpoint('Find The Sample Message', 'Return the sample message.')] #[UrlParam('id', 'integer', 'The ID of the message.')] public function find(int $id): SampleMessageResource { $message = SampleMessage::findOrFail($id); } Laravel Live Japan 2026 14
  13. Other Powerful Scribe Features #[Endpoint()] : Add an endpoint description

    #[UrlParam()] : Add details for a URL parameter #[QueryParam()] , #[BodyParam()] : Add query and body parameter details #[ResponseFromApiResource()] : Generate a response example from ApiResource and more… #[Endpoint('Find The Sample Message', 'Return the sample message.')] #[UrlParam('id', 'integer', 'The ID of the message.')] #[ResponseFromApiResource(SampleMessageResource::class, SampleMessage::class)] public function find(int $id): SampleMessageResource { $message = SampleMessage::findOrFail($id); return new SampleMessageResource($message); } Laravel Live Japan 2026 14