Skip to main content

One of the most important but overlooked things is to document your API for future clients, whether they would come from a JS front-end, or a mobile app. Things like:

  • Endpoints
  • Parameters
  • Auth mechanism
  • Example responses

Luckily, there are a few Laravel packages that allow you to generate such docs automatically. You configure things you need, by modifying the config file and adding some comments to your routes/controllers, then you run an Artisan command, and it saves the static HTML files to a public folder on your server. As a result, you can just send the link to it, to your API consumers.

My personal favorite package for this is called Scribe, and we will use exactly that one.

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 09 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

R
rafa1944 ✓ Link copied!

Thanks Povilas, very good resource!! Let's go for the second part? like Front-ent integration or payment? haha keep the good job!

GK
Gavin Kimpson ✓ Link copied!

I second the frontend integration!

PK
Povilas Korop ✓ Link copied!

Front-end integration tutorials for Vue and React are already in progress, for February :)

A
andywong31 ✓ Link copied!

im excited for the front-end integration! thanks Povilas!

GK
Gavin Kimpson ✓ Link copied!

I will try to be as active as Andy in the comments too :) Look forward to the frontend integration - i'm doing a frontend integration in Vue now so it will be good to compare my 'attempt' to yours (your frontend will be a 100x better I am sure lol)

PK
Povilas Korop ✓ Link copied!

@Gavin I'm not a front-ender at all, so I wouldn't fully count on my implementation being better :)

GG
Gabor Gazdag ✓ Link copied!

Thank you! Very nice tutorial!

GK
Gavin Kimpson ✓ Link copied!

Still debugging this - however when I run the php artisan scribe:generate command I get the following error, anyone else had the same problem? P.S I added the @group <Controller> code to each controller

/**
* @group Auth
*/

Output from VS Code

ErrorException
 
Undefined array key 1
 
at vendor/knuckleswtf/scribe/src/GroupedEndpoints/GroupedEndpointsFromApp.php:223
219▕
220▕ private function isValidRoute(array $routeControllerAndMethod = null): bool
221▕ {
222▕ if (is_array($routeControllerAndMethod)) {
➜ 223▕ [$classOrObject, $method] = $routeControllerAndMethod;
224▕ if (u::isInvokableObject($classOrObject)) {
225▕ return true;
226▕ }
227▕ $routeControllerAndMethod = $classOrObject . '@' . $method;
 
+18 vendor frames
19 artisan:35
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
GK
Gavin Kimpson ✓ Link copied!

Weirdly - I cloned your copy of the Laravel car parking app from github and ran the scribe command and it works fine... so there is something weird with mine i'll try to dig more into it over the weekend

PK
Povilas Korop ✓ Link copied!

Yeah, again, I can't debug what I haven't encountered myself. Let us all know if you find the difference. That's, by the way, the downside of all those auto-generating tools: you need to be precisely careful with how your docblocks are written.

GK
Gavin Kimpson ✓ Link copied!

I'm not so fussed with the error above as I can always use your original repo, but I have gained a lot of insight especially with the phpunit tests! Thanks I really enjoyed this one a lot :)

PK
Povilas Korop ✓ Link copied!

Well, I didn't plan the hightlight of this course to be the TESTING lesson, added it as a bonus mostly, but... whatever works! :)

AA
Ali Al Qahtani ✓ Link copied!

Very good course

PK
Povilas Korop ✓ Link copied!

Thanks Ali!

EC
Elmar Cabbarlı ✓ Link copied!

Thank you for the course. I love writing clean code and the course reflects that. So, i have a question, I want to create laravel api and apply authorization. i discovered sanctum from this course and confused for authorization. I used to spatie laravel permission package for authorization. But there is a similar option in sanctum which is abilities. So i want to ask that or please give me advice for this, what should i use for authorization? or what do u use for authorization?

PK
Povilas Korop ✓ Link copied!

Personally, I've never used Sanctum abilities, only spatie/laravel-permission. I'm not sure if those abilities would work the same, I'm just used to the package that I've been using for years now.

A
abphaiboon ✓ Link copied!

Awesome course :) Thank you.

H
haritjahjo ✓ Link copied!

Thank you Povilas.

NS
Ngozi Stephen Onyemauche ✓ Link copied!

Thank you Povilas, awesome course

P
porrapat ✓ Link copied!

Thank you, this is good course!

P
porrapat ✓ Link copied!

Are you forget @group Auth in LogoutController?

PK
Povilas Korop ✓ Link copied!

Yes, good point, forgot about that, but now too much work to change and re-do the screenshots :)

MB
mohannad banattaf ✓ Link copied!

Hello and thanks for the course. I have a question altho regarding "response_calls", did it change name because i cant find it.

JA
Jim Adamek ✓ Link copied!

Thanks for recommendation for Scribe to produce API documents. I was looking for a more automated solution. You do a great job of pointing us in the right direction with your examples and how to...

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.