API Versioning - How to make a Laravel CRUD API #6

  Рет қаралды 12,277

Quentin Watt Tutorials

Quentin Watt Tutorials

Күн бұрын

Пікірлер: 42
@KenuraTech
@KenuraTech Жыл бұрын
Thanks. this video is usefull. still working after 4 years. very valuable.
@danishmehmood6110
@danishmehmood6110 5 жыл бұрын
this channel has the potential to become the best
@QuentinWatt
@QuentinWatt 5 жыл бұрын
Thank you
@oriksgaming8383
@oriksgaming8383 3 жыл бұрын
The 3 people that disliked love plain PHP. Great tutorial!
@QuentinWatt
@QuentinWatt 3 жыл бұрын
Thank you!
@jmares79
@jmares79 4 жыл бұрын
Thanks for the video! It really helped to figure out a versioning strategy. One question that arise is what would be the best way to version with different Form validation request resources. One idea is to have all separated by folder version but again, DRY comes to question it. Also, looking at the controllers code, they'll be pretty similar, so duplicating them seems like a "waste". Any ideas how can I separate by version, each of them with a different Form request validation class?
@QuentinWatt
@QuentinWatt 4 жыл бұрын
I don't really like the concept of DRY. A lot of the time beginners take this way too seriously and try to make 1 function do far too much stuff and you land up with a Spaghetti function without a defined purpose. It's okay to have some repeated code here and there as long as it's for different resources that have different responsibilities. Those responsibilities often change and morph away from each other at the project grows and having some repeated code allows for that growth. You're probably not making simple changes between versions anyway. So the approach won't land up having much repetition.
@Zorish373
@Zorish373 4 жыл бұрын
Thanks! This was super useful for the Rest API I'm doing, using all of these tricks! Wish we had more info on customizing input when creating users and such, like auto UUID and relationships with foreign id!
@QuentinWatt
@QuentinWatt 4 жыл бұрын
It’s documented in Laravel’s docs if you don’t mind reading a bit.
@christostsangaris4785
@christostsangaris4785 5 жыл бұрын
Great video @Quentin! Just a question: Is there a way to tackle code duplication (keep things DRY) in case we have one PersonController returning views building up a page for the website and one Api\v1\PersonController returning JSON data for consuming API by a mobile app? Because the way I see it, separating the controllers is a good thing, but then again both controllers will have common code. Thanks!
@QuentinWatt
@QuentinWatt 5 жыл бұрын
Use 2 controllers. Sometimes DRY can be taken too far. If the use cases are different, like in your case, with Web and API routes, then it's more than okay to have some duplication. What you could do if you really wanted, is create a Laravel use case, and use the same use case in both the web controller and the api controller.
@adilismail3593
@adilismail3593 5 жыл бұрын
Jwt or oauth for rest apis
@Sortepr
@Sortepr 5 жыл бұрын
Great tutorial, learned a lot :)
@QuentinWatt
@QuentinWatt 5 жыл бұрын
I'm so glad to hear that.
@TyreeArt
@TyreeArt 5 жыл бұрын
Is there some particular reason when you made the controller you put it under Api/v1, but the Resource was just v2 instead of Api/v2? Did you have to have the "Api" folder?
@QuentinWatt
@QuentinWatt 5 жыл бұрын
It's possible I could have controllers for web routes, and controllers for API routes which can very often perform completely different tasks but might be named similar. So I like to have those separated with a folder so I know the difference. Resources will be used as resources, no matter if it's through the API or through a web route. So those don't need such division.
@kendallarneaud
@kendallarneaud 3 жыл бұрын
@@QuentinWatt What it not be possible to use it still while keeping the OP's proposed structure? How tedious is it to keep track if it were being done to Models and Requests?
@tareqabughoush9196
@tareqabughoush9196 4 жыл бұрын
Can I ask you why haven't you extended the v2 resources from v1? I mean, in some cases, the developer won't have to redo the whole apis, just some minor changes or updates, the copy pasting looks a bit messy. Just extend the original controller and override the functions with new updates or changes, sounds good?
@QuentinWatt
@QuentinWatt 4 жыл бұрын
Personally I'd like them to be completely separated as we're simply returning an array, and I don't want to do extra digging to find keys I'd expect to see in v2 api resource. But how you do things is entirely up to you.
@ShahZaib-dm1bh
@ShahZaib-dm1bh 2 жыл бұрын
I have named routes, how should I handle routes? As we can't have routes with same name. "Error: Another route has already been assigned name". Please guide
@QuentinWatt
@QuentinWatt 2 жыл бұрын
Give it another name 🙃
@creative-commons-videos
@creative-commons-videos 5 жыл бұрын
can i version whole app instead of just controller, like what about repository, models, etc these can also be changed depended on v1 and v2 changes, is there any way to version full app ? like laravel/v1/applaravel/v2/app, where app contains all the things like models, controllers, repositories etc
@QuentinWatt
@QuentinWatt 5 жыл бұрын
😕 not sure what you're trying to ask. This is an API that can have different versions of returned data on different endpoints. It's always the same API, so that's not versioned, only the end points are. What it sounds like you're asking, is you multiple versions of an API? Which doesn't really have a very useful real world use case (that would be worth managing anyway), but in that case you set up 2 different Laravel Apps on separate subdomains.
@kendallarneaud
@kendallarneaud 3 жыл бұрын
@@QuentinWatt What about version Middleware or Requests or even Models do you version Models and Middleware or do you cater for backward compatibilities?
@rakeshkv1170
@rakeshkv1170 5 жыл бұрын
what if we want do lots of logic inside this function, then how to use the resource, Can generate resource collection for each function
@QuentinWatt
@QuentinWatt 5 жыл бұрын
You should try not to do a lot of logic in this function because it will slow down your API response time quite a bit. It'll be better to set up your Models and Relationships properly so you execute as little logic as possible. You can make use of Laravel "Use Cases" if needs be.
@rakeshkv1170
@rakeshkv1170 5 жыл бұрын
@@QuentinWattI have 2 DB connection to my model. I'll get all the data after that I have to extract data to visualize based on the region and date & time. It contains pretty big logic. May Be I have to create some private functions to keep the logic small.
@Stoney_Eagle
@Stoney_Eagle 5 жыл бұрын
Man you realy make me work for it tho haha, while im at it why not add more rows to the table? I already have a laravel install that was build from front to back, now i want to do it right and start with the backend. The api route scheme i had was Route::group(['prefix' => '/v1', 'namespace' => 'Api\V1', 'as' => 'api.'], function () { Route::apiResource('/person', 'PersonController'); }); I just wrapped my version around it, Laravel is just that easy. Your tutorial has been a joy so far, i just hope you stop burning my eyes in future videos (Postman is the onlything white and it BURNZZZ 🤣🤣) Anyways i'll keep folowing the rest Thanks so far 😉
@QuentinWatt
@QuentinWatt 5 жыл бұрын
hah don't be so quick to hate light themes :p
@Stoney_Eagle
@Stoney_Eagle 5 жыл бұрын
@@QuentinWatt I don't hate white themes 😂😂 My eyes just hurt everytime you switch from a black to white screen.
@kendallarneaud
@kendallarneaud 3 жыл бұрын
Why not "group" the version related files together? e.g. You have App\Http\Controller\v1 and App\Http\Resources\v1 ... Why not App\v1\Http\Controller\... and App\v2\Http\Resources\... App\v2\Models\.... ?
@QuentinWatt
@QuentinWatt 3 жыл бұрын
I don't think you would really want to manage 2 different models. This would be completely unnecessary. Versioning the resource would be required for backwards compatibility which you can eventually phase out when you decide you have moved all your API consumers to the new version.
@fernandogpz
@fernandogpz 5 жыл бұрын
what about form requests?
@QuentinWatt
@QuentinWatt 5 жыл бұрын
You can use these for forms. Form requests from an actual website will be done in a future tutorial series.
@eloquent2200
@eloquent2200 2 жыл бұрын
Thank you!
@QuentinWatt
@QuentinWatt 2 жыл бұрын
You're welcome!
@daviddeleon3411
@daviddeleon3411 5 жыл бұрын
SIR THANK YOU :) :) :) :) :)
@QuentinWatt
@QuentinWatt 4 жыл бұрын
It's a pleasure :)
@pl_ro
@pl_ro 2 жыл бұрын
👍
@QuentinWatt
@QuentinWatt Жыл бұрын
I appreciate that.
@AniketSomwanshi-ll7mz
@AniketSomwanshi-ll7mz 5 жыл бұрын
thanks
@QuentinWatt
@QuentinWatt 5 жыл бұрын
:) It's a pleasure.
Final video - How to make a Laravel CRUD API #7
1:34
Quentin Watt Tutorials
Рет қаралды 5 М.
Rest API - Best Practices - Design
15:50
High-Performance Programming
Рет қаралды 115 М.
Chain Game Strong ⛓️
00:21
Anwar Jibawi
Рет қаралды 41 МЛН
人是不能做到吗?#火影忍者 #家人  #佐助
00:20
火影忍者一家
Рет қаралды 20 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
Laravel Validation: 12 Less-Known Tips in 13 Minutes
13:11
Laravel Daily
Рет қаралды 38 М.
Setting up a new Laravel project - How to make a Laravel CRUD API Tutorial #1
11:02
Seeding fake data with a factory - How to make a Laravel CRUD API Tutorial #2
11:41
Scaling our Laravel app, after a flash sale took down our MySQL database
6:23
Laravel 11 Routing: API, Versioning and Custom Routes
5:06
Laravel Daily
Рет қаралды 16 М.
Simple Custom Laravel Logging
7:50
Codecourse
Рет қаралды 28 М.
Securing a Laravel API in 20 minutes with JWTs
20:36
Andrew Schmelyun
Рет қаралды 79 М.
Samsung Galaxy S25 Ultra - Here Are The New Features
4:49
TechTalkTV
Рет қаралды 10 М.
05 - Token-based Authentication
12:52
Laravel
Рет қаралды 27 М.