The Right Way To Build REST APIs

  Рет қаралды 43,822

Awesome

Awesome

7 күн бұрын

Best Practices for building REST APIs.
💬 Topics:
1. Richardson Maturity Model;
2. Stateless vs Stateful APIs;
3. Define correct REST Endpoints;
4. REST Endpoints responses;
5. Plain Text vs JSON vs XML vs YAML;
6. Handling exceptions in APIs;
7. REST API versioning;
8. HATEOAS
9. The HTTP protocol;
🥇 Become a Member - / @awesome-coding
✉️ Join the Newsletter - newsletter.awesome.club/

Пікірлер: 148
@RoelCagantas
@RoelCagantas 5 күн бұрын
Poor Fireship clone.
@omergatenio6802
@omergatenio6802 4 күн бұрын
Yeah, you're right. It's really unfortunate that we receive a well explained top-notch content in a format similar to Fireship. What a disgrace!
@dotnetapp
@dotnetapp 4 күн бұрын
pin of shame
@RazoBeckett.
@RazoBeckett. 4 күн бұрын
@@dotnetapp ya lol
@2u841r
@2u841r 4 күн бұрын
Poor rest-api concept clone. Poor Talking with English language clone. Poor Breathing Clone. Poor Living on the earth Clone.
@ChichaGad
@ChichaGad 3 күн бұрын
@RoelCagantas someone's mad
@vexxxG
@vexxxG 5 күн бұрын
Personal opinion: a restful endpoint should be /api/orders/123/items?status=active or something along those lines. The path should only refer to resources by name or identifier, since active items returns a subset of a specific resource it should be used in the query string since it is a filter. Also, according to the spec, PUT is for upserting not only updating. PATCH is for updates only
@ptinosq
@ptinosq 4 күн бұрын
Not a personal opinion - that's the industry standard 😅
@lucaruana9404
@lucaruana9404 5 күн бұрын
I've been trying to learn API dev for a while now and this is the simplest and most crystal-clear video I've ever stumbled upon. Thanks a lot!
@awesome-coding
@awesome-coding 5 күн бұрын
Glad it helped! Thanks for the feedback!
@br3nto
@br3nto 5 күн бұрын
<a href="#" class="seekto" data-time="428">7:08</a> RESTful APIs can return HTML too! Like HTMX suggests, there is nothing more HATETOAS than HTML with its natural support for links and forms etc
@peterszarvas94
@peterszarvas94 4 күн бұрын
9:55 "no accepted standard' literally HTML is the standard
@cslearn3044
@cslearn3044 5 күн бұрын
I recently quit web dev but i still come here watching cuz its interesting, and to like
@awesome-coding
@awesome-coding 5 күн бұрын
Thank you! Why did you quit web dev?
@cslearn3044
@cslearn3044 5 күн бұрын
@@awesome-coding no creativity, or you follow a specific path or your site will be bad, so yeah
@Hardware-pm6uf
@Hardware-pm6uf 5 күн бұрын
​@@cslearn3044 what do you mean by creativity ? Web dev isn't creative
@Serizon_
@Serizon_ 5 күн бұрын
@@cslearn3044 there are a 1000 specific paths , so generally people just use what they like.
@bhumit070
@bhumit070 5 күн бұрын
@@cslearn3044so what are you doing/pursuing now?
@axMf3qTI
@axMf3qTI 5 күн бұрын
You know what drives me crazy. websites that serve a 404 page with a 200 status code. What are you doing with your life?
@GraphiteSC
@GraphiteSC 4 күн бұрын
Are those sites built with a framework or library like React? For SPA’s, the router is responsible for rendering your app, nothing else, and without it your app won’t be found/initiated/rendered. Netlify, Nginx, Vercel etc. all need to defer that 404 responsibility (all routing responsibility), to the SPA’s router - and the only way to do that, is to tell the service to always return a 200, and redirect to your project’s entry point (index) so the router can load and do its thing.
@Dipj01
@Dipj01 4 күн бұрын
A REST API typically doesn't return a "page". The 404 page that you see is given from the spa framework itself if your requested path doesn't match one of its predefined paths/patterns. If you make that request through Postman, you'll still likely get the 404 status in response.
@GraphiteSC
@GraphiteSC 4 күн бұрын
@@Dipj01 Yeah, that’s what I’m saying. His condition can only happen on the front-end, with a SPA - and there’s a reason why that I was trying to explain.
@axMf3qTI
@axMf3qTI 4 күн бұрын
@@Dipj01 Oh you mean because this video talks about APIs. I meant when there is no API and you have to scrape a little for example. Would be nice if things work how they are designed to work.
@jeremysollars5922
@jeremysollars5922 5 күн бұрын
Your description of HATEOAS is unfortunately flawed. It shouldn't return JSON but should opt purely for HTML. In reality this is the true definition of REstful, html is restful, json isnt. Somehow this got lost in the sauce.
@maguilecutty
@maguilecutty 3 күн бұрын
Awesome content! The knit pickers here can jump in a lake. It’s so hard to find actual production grade info like this! Chapeau 😊
@awesome-coding
@awesome-coding 3 күн бұрын
Thank you!
@jaimieomondi1449
@jaimieomondi1449 5 күн бұрын
The only words that i have heard today that make sense have come from this video...Greatly appreciated.
@awesome-coding
@awesome-coding 5 күн бұрын
Wow, thank you!
@buddy.abc123
@buddy.abc123 5 күн бұрын
Awesome, thanks! I thought you were gonna squeeze it into a 3 minute video but I was pleasantly surprised to see it go on until I checked the video length 😅
@awesome-coding
@awesome-coding 5 күн бұрын
Glad you liked it! I'm planning to shift more towards the 10 minute format.
@wotwithbert7591
@wotwithbert7591 4 күн бұрын
HATEOAS should ultimately return hypermedia, not JSON that has to still be parsed on the client (with some additional logic being applied to the data being returned from the server, in some cases (especially on big tech projects)). Ultimately I believe that not responding with a pure declarative HTML response results in most REST APIs being more REST-like, than RESTful. Am I wrong to assume that?
@ashleyfreebush
@ashleyfreebush 19 сағат бұрын
very well explained...thanks awesome!!
@awesome-coding
@awesome-coding 18 сағат бұрын
Thank you!
@SuperKavv
@SuperKavv 5 күн бұрын
Great video! Really clear explanation.
@awesome-coding
@awesome-coding 5 күн бұрын
Glad it was helpful!
@TalesGrechi
@TalesGrechi 5 күн бұрын
Great video!
@debadipti
@debadipti 5 күн бұрын
Simply Awesome!
@awesome-coding
@awesome-coding 5 күн бұрын
Glad you like it!
@oogway_hussein
@oogway_hussein 5 күн бұрын
thank you, keep up the high quality content
@awesome-coding
@awesome-coding 5 күн бұрын
Thanks, will do!
@sinamobasheri
@sinamobasheri 5 күн бұрын
The Hub 🥃 lol
@awesome-coding
@awesome-coding 5 күн бұрын
Well they have millions of visits each month so it must be up there, right? :))
@harshrathod50
@harshrathod50 5 күн бұрын
Very informative, thanks. 🎉
@awesome-coding
@awesome-coding 5 күн бұрын
Glad it was helpful!
@AboinTech
@AboinTech 5 күн бұрын
loved it. made visually and content vise with good quality.
@awesome-coding
@awesome-coding 5 күн бұрын
Glad you liked it!
@solorsix
@solorsix 5 күн бұрын
Nice work!
@awesome-coding
@awesome-coding 5 күн бұрын
Thank you! Cheers!
@sebs4591
@sebs4591 5 күн бұрын
Great video. Just note REST isn’t the *only* option. RPCs can be great for internal API calls
@awesome-coding
@awesome-coding 5 күн бұрын
You just guessed what one of my next videos will be about :D
@acopier
@acopier 4 күн бұрын
also GraphQL
@em9999999
@em9999999 4 күн бұрын
The representation of backend and frontend developers is spot on
@koenv85
@koenv85 5 күн бұрын
My preference would be to have a query parameter of status = active instead of putting active in the URL
@awesome-coding
@awesome-coding 5 күн бұрын
That's fair - a valid alternative.
@anfytrion
@anfytrion 5 күн бұрын
Great explanation 👏and as always great video
@awesome-coding
@awesome-coding 5 күн бұрын
Thank you!
@ChichaGad
@ChichaGad 5 күн бұрын
This was so clear and on point Next, please do GraphQL
@awesome-coding
@awesome-coding 5 күн бұрын
Thank you!
@ChichaGad
@ChichaGad 3 күн бұрын
​@@awesome-codingGood luck! ❤
@rsjeyt
@rsjeyt 4 күн бұрын
this was great
@awesome-coding
@awesome-coding 4 күн бұрын
Thank you!
@erroneousbee
@erroneousbee 2 күн бұрын
I like the way dealing with state was just handwaved away. Also very much enjoyed the skewer-case, cos using snake_case maps too easily to js varnames.
@vpetryniak
@vpetryniak 5 күн бұрын
I wonder how to get a job at “The Hub” company
@awesome-coding
@awesome-coding 5 күн бұрын
You need to really know the product first.
@novo99
@novo99 5 күн бұрын
I like to send 404 instead of 403 because I believe that the client should only be aware of resource that they have access to and 403 shows that the resource exists.
@awesome-coding
@awesome-coding 5 күн бұрын
Yes and no:D I understand the benefit of the added security, but think about this scenario: You are working with a 3rd party API and somehow you have your credentials wrong. You make the request and a 404 Not Found is returned. You go back to the documentation and double check the URL. Make the call again - 404 again. It's more likely to thing that there is a bug in the API / documentation than an authentication issue on your part.
@2u841r
@2u841r 5 күн бұрын
Very helpful
@awesome-coding
@awesome-coding 5 күн бұрын
Glad it helped!
@bige2899
@bige2899 4 күн бұрын
What makes me astonished is how many well-known websites uses 400 bad request as a standard 4xx status code , 400 should be used only when there is a syntax error in request payload.
@bige2899
@bige2899 4 күн бұрын
What makes me astonished is how many well-known websites uses 400 as a standard 4xx status code , 400 should be used only when there is a syntax error in the request payload.
@biovawan
@biovawan 5 күн бұрын
Great video! Thank you! Could you please make a video describing hateoas more in detail?
@awesome-coding
@awesome-coding 5 күн бұрын
Thanks you! Will post more detailed videos soon.
@bobDotJS
@bobDotJS 5 күн бұрын
It took me 4 years of trial and error, and working with teams to absorb all of this knowledge through osmosis.
@moveonvillain1080
@moveonvillain1080 5 күн бұрын
is HATEOAS backend driving frontend kind of design or these two are different things?
@HansWurst-dk6pp
@HansWurst-dk6pp 5 күн бұрын
I heavily disagree with the content of the video at 4.43. You should never just crerate CRUD endpoints around resources. Instead you should always prefer actions. The backend does highly diverse actions to the resources. The frontend should just tell the backend to do them, by calling an appropriate endpoint.
@bijeesraj007
@bijeesraj007 5 күн бұрын
I totally agree with the use of actions , In my opinion they should be exactly same as it mentioned in the video . HTTP verb + resource name = intended action . The resources should be nouns not actions .
@Kubkochan
@Kubkochan 5 күн бұрын
​@@bijeesraj007gl
@DeviantFox
@DeviantFox 2 күн бұрын
so much hate but I really fucking liked this video.
@MarcoDamaceno
@MarcoDamaceno 4 күн бұрын
HATEOAS maturity can be achieved by returning HTML instead of JSON. Then the client can parse the response or pick a part that is interesting like the url for example.
@MrSofazocker
@MrSofazocker 5 күн бұрын
Im the CEO of HTMX and approve! HATEOAS for everyone!
@Shivam-sl4sp
@Shivam-sl4sp 5 күн бұрын
which software do you use for editing?
@awesome-coding
@awesome-coding 5 күн бұрын
Adobe premiere pro
@sire_ns
@sire_ns 5 күн бұрын
wow!
@n8o_
@n8o_ 5 күн бұрын
HTMX was made with the goal of extended HTML to be a complete hypermedia. It abides by the HATEOAS model, and is a simple and effective way to put it into action
@2coding
@2coding 4 күн бұрын
This is the best REST api video on youtube!
@awesome-coding
@awesome-coding 4 күн бұрын
Thank you!
@manuelvega.
@manuelvega. 5 күн бұрын
Don't forget the meta data in the response!
@harrisonkaiser5138
@harrisonkaiser5138 5 күн бұрын
What’s the solution if we need to specify more than two levels in the URL to specify complex relationships?
@follantic
@follantic 5 күн бұрын
RPC style naming. Because there's no indirection most of the problems with REST don't exist.
@awesome-coding
@awesome-coding 5 күн бұрын
There is no hard rule of thumb. As you can see in the comments, people bend and interpret some of these rules. You can have more than two levels if that's really needed, but it should be on very specific cases. If you have a concrete example we can discuss it.
@bphilsochill
@bphilsochill 5 күн бұрын
Source material?
@vuenice
@vuenice 5 күн бұрын
[<a href="#" class="seekto" data-time="319">5:19</a>] why Django has forward slash by default included in routes then?
@awesome-coding
@awesome-coding 5 күн бұрын
I guess we would have to ask them :D
@naranyala_dev
@naranyala_dev 5 күн бұрын
hypermedia mentioned
@user-nu5eu6ih1r
@user-nu5eu6ih1r 3 күн бұрын
then what is the right uri for login,sign in
@awesome-coding
@awesome-coding 2 күн бұрын
You found some of the exceptions :). I usually go with: - /api/v1/auth/login - /api/v1/auth/register - /api/v1/auth/sso/authorize - /api/v1/auth/sso/callback
@hellowill
@hellowill 4 күн бұрын
Always add versioning
@ludovicabomo9674
@ludovicabomo9674 2 күн бұрын
🙂
@simpingsyndrome
@simpingsyndrome 5 күн бұрын
Soo does it means laravel frameworks by default is a level 3 REST API? I recently have collaborated with a PHP guy develop an API using laravel, the best practices that he implement based on my understanding in this video, he implement too many slugs, and no single one query params, I think it's confusing for me as Frontend developer, aven though I read the API docs over and over I still didn't get it, what the hell is representating the every /a/b/c ,even on a very simple use case the API just give a response like completely annoying to read,there are many links,pages etc which is not even consumed, he even make an infinite breaking changes that breaks feature that already done, what a horrible PHP guy to collaborate with.
@_Aarius_
@_Aarius_ 5 күн бұрын
only level 3 is REST. everything else is just RPC with specific constraints
@netssrmrz
@netssrmrz 5 күн бұрын
Good video. But for IPC, REST is a half baked piece of cow poo. Maybe one day we'll have a proper binary API protocol that runs alongside HTTP with built in auth, discoverability, param marshalling, autogenerated client stubs, and we won't have to give a dam about the networking internals.
@qvxactgcw
@qvxactgcw 5 күн бұрын
Which text to speech app you use?
@dynamohack
@dynamohack 5 күн бұрын
hateos is just a simple mpa app made using php or any other backend language
@awesome-coding
@awesome-coding 5 күн бұрын
I'm not sure what that means exactly.
@dynamohack
@dynamohack 5 күн бұрын
@@awesome-codingmpa is multi page application and all mpa most of the time uses hyper mean of all engine shit
@liquidrider
@liquidrider 4 күн бұрын
was this a advertisement I seriously can't tell
@awesome-coding
@awesome-coding 4 күн бұрын
Avertisment to what? :))
@Seedwreck
@Seedwreck 5 күн бұрын
Fireshippilled
@ryo_5748
@ryo_5748 5 күн бұрын
The easiest way to build a great Rest API is to provide the same API as DummyJSON 😄
@awesome-coding
@awesome-coding 5 күн бұрын
Fair
@tincoandringa4630
@tincoandringa4630 5 күн бұрын
Pro-tip: Never progress to level 3 of the richardson maturity model. HATEOAS has never benefited anyone in the history of HTTP.
@awesome-coding
@awesome-coding 5 күн бұрын
I agree - it's more of a theoretical level.
@StingSting844
@StingSting844 5 күн бұрын
I don't agree. We converted around 10 pages in our product with htmx in just 2 weeks. This would have taken at least a quarter if it was just react + APIs. We actually had time to focus on details and literally everyone asked how these pages are loading faster 😂
@sandiprai1383
@sandiprai1383 5 күн бұрын
Why? Can you explain it
@awesome-coding
@awesome-coding 5 күн бұрын
@@sandiprai1383 I mentioned the main reasons at the end of the video: - Not as performant / efficient since you are sending over the wire more bytes than necessary. Consider the option that HATEOAS links could have 10-15 entries; - Not widely adopted. Other than some public APIs I worked with in the past, everybody pretty much sticks to level 2. This is especially true in any software that's not open, since you don't really need self discoverable APIs - it' easier for the client to just map to whatever the API is - It is not really an enforced standard, which, in all fairness, it is true about pretty much any architecture / tech since it is very tough to enforce standards on the web :D
@markyip554
@markyip554 5 күн бұрын
Isn't traditional 'SSR multi page' web applications fulfill this level by default?
@QueeeeenZ
@QueeeeenZ 5 күн бұрын
I prefer GraphQL for the type safety.
@krellin
@krellin 5 күн бұрын
no matter how you do it if its REST its shit most casual systems should use grpc just for sake of compile time type safety and performance they get for free
@azulamazigh2789
@azulamazigh2789 5 күн бұрын
/items?active=1
@awesome-coding
@awesome-coding 5 күн бұрын
Maybe /items?status=active? In your example one could call 1 a "magic number" :)
@azulamazigh2789
@azulamazigh2789 5 күн бұрын
@@awesome-coding yes I agree with you
@L4B5
@L4B5 4 күн бұрын
`active` should go as a filter param to items resource: orders/123/items?filter=active
@peterszarvas94
@peterszarvas94 4 күн бұрын
/api/orders/123/items?filter=active or: /api/orders/123/items?active=true
5 Modern Features That Make CSS Easy
3:49
Awesome
Рет қаралды 12 М.
Intel's CPUs Are Failing, ft. Wendell of Level1 Techs
23:59
Gamers Nexus
Рет қаралды 25 М.
Khó thế mà cũng làm được || How did the police do that? #shorts
01:00
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 90 МЛН
Was ist im Eis versteckt? 🧊 Coole Winter-Gadgets von Amazon
00:37
SMOL German
Рет қаралды 36 МЛН
I wish I could change THIS fast! 🤣
00:33
America's Got Talent
Рет қаралды 126 МЛН
What We Learned From the Polyfill Attack
3:01
Awesome
Рет қаралды 18 М.
Progressive Web Apps in 2024
4:07
Awesome
Рет қаралды 35 М.
The Easiest Way to Build Web Apps
3:26
Awesome
Рет қаралды 35 М.
Rest API - Best Practices - Design
15:50
High-Performance Programming
Рет қаралды 100 М.
Build A Food Safety Application With Llama2
2:56
CuriosityTech
Рет қаралды 66
Turns out REST APIs weren't the answer (and that's OK!)
10:38
Dylan Beattie
Рет қаралды 58 М.
There's A New Browser (That ISN'T Chrome Based)
47:59
Theo - t3․gg
Рет қаралды 95 М.
100+ Linux Things you Need to Know
12:23
Fireship
Рет қаралды 710 М.
Khó thế mà cũng làm được || How did the police do that? #shorts
01:00