Build a RESTful API with Fastify, Prisma & TypeScript

  Рет қаралды 62,851

TomDoesTech

TomDoesTech

Күн бұрын

Пікірлер: 101
@mrclean2086
@mrclean2086 2 жыл бұрын
Really great tutorial! The biggest thing I liked is the (rare) nicety of detailing which things are for demo purposes, AND THEN giving an idea of what you'd actually do in production. It really showcases just how much you know what you're talking about, and provides new users an alternative if they're building production applications. This is really great content and the time just flies by, thank you for producing such high quality content!
@TomDoesTech
@TomDoesTech 2 жыл бұрын
Thank you! That is very generous of you, my first KZbin donation.
@Andres-it2du
@Andres-it2du Жыл бұрын
I'm a frontend dev and I wanted to get my feet wet with some backend stuff and this video was exactly what I was looking for. Well prepared, decently fast-paced, and finally a tutorial for people who are not complete beginners. Fantastic job Tom, thank you very much!
@andremazetto
@andremazetto 8 ай бұрын
This video has been so important to me and my journey. I've spent hours dissecting each part of it and expanding/adapting to my needs. I was able to build a bad arse API to power the front end app. I never seen a video as thorough as this!!!
@TomDoesTech
@TomDoesTech 8 ай бұрын
Thank you so much! I'm glad it helped :)
@andrewriefenstahl2930
@andrewriefenstahl2930 2 жыл бұрын
Tom you did a wonderful job. I'm learning TypeScript now and this video made me realize the advantages of a superset language in regards to node development. Keep up the good work.
@TomDoesTech
@TomDoesTech 2 жыл бұрын
Glad it was helpful!
@rubennijhuis
@rubennijhuis Жыл бұрын
Honestly one of the best tutorials I have ever seen. Starting from a more intermediate-advanced level. Understanding that the audience should know the difference between what is important for development vs production and explaining everything in a clear and consize way. You earned a new subscriber and helped me tremendously with setting up the API for the start-up I am working with.
@andreaskuthe3866
@andreaskuthe3866 2 жыл бұрын
Great! As I am a beginner with fastify and api's, this is a great tutorial! Comprehensive explanation and very satisfying results. Thanks a lot!
@TomDoesTech
@TomDoesTech 2 жыл бұрын
Glad it was helpful!
@sidharthmohanty2538
@sidharthmohanty2538 2 жыл бұрын
You are GOAT! Please keep making such videos
@zombiefacesupreme
@zombiefacesupreme Жыл бұрын
Fantastic video, Tom!! Other than a few things being slightly out of date (other users should check the pinned posts comments for details), I really enjoyed how you walked through this. I really like the way things are laid out with Fastify. It all rhymes with Express, but I needed something like this to really feel equipped building servers in the future.
@JeffLevyForPresident
@JeffLevyForPresident 2 жыл бұрын
Once again, Tom, you knock it out of the park. Sorry. Gratuitous baseball metaphor. Great video. I just spent a few weeks doing your mongo API video, shaking things up here and there, trying to explore more of the ecosystem. Great stuff. This one? Wow. Lots of time and thought went into this. THANKS!
@tarik3958
@tarik3958 2 жыл бұрын
Guys his Discord is gold!
@euanmorgann
@euanmorgann 2 жыл бұрын
I would love to see more fastify videos, this is the best one out there by far 🙌
@austinevick
@austinevick Жыл бұрын
I started following you few weeks ago and I can say that you have one of the best tutorials and video quality out there. I love the uniqueness and the way you approach things, I believe my nodejs skills will greatly advance by following your courses. Thank you once again.
@rorycawley
@rorycawley 2 жыл бұрын
This is like poetry, amazing clarity - thank you Tom
@TomDoesTech
@TomDoesTech 2 жыл бұрын
Glad you enjoyed it!
@Vengeanceway
@Vengeanceway 2 жыл бұрын
Man, I’m just in love with your tutorials. Keep on creating amazing content ❤️
@MrKeepItTrill
@MrKeepItTrill 2 жыл бұрын
Great video!! I’m the person who asked for it on Discord and finally had the time to watch it :) One thing I noticed is, at 1:17:43 the Products don’t have the owner on them even though they are defined to do so in product.service. I fixed it by exporting userCore from user.schema, and adding `owner: z.object(userCore),` to productGenerated in product.schema. The only thing I’m not sure of is, in terms of design is exporting userCore the way to go here or would you be better off creating something like a productOwnerSchema?
@johnnydriesen7575
@johnnydriesen7575 2 жыл бұрын
Same here. Thanks for you solution, @MrKeepItTrill. Though, I also want to know if this is the way to go...
@partiid
@partiid Жыл бұрын
I really like the approach you took. Simple yet very informational because you are making almost everything from scratch except for the things you are explaining.
@TomDoesTech
@TomDoesTech Жыл бұрын
Glad it was helpful!
@valirjonathan2161
@valirjonathan2161 2 жыл бұрын
Thank you very much. Please make another video about Fastify.
@MaksymMinenko
@MaksymMinenko 2 жыл бұрын
This video is absolutely amazing! A hidden highly underrated gem...
@aayushbisen
@aayushbisen 2 жыл бұрын
I am following this tutorial using supabase's database. If anyone is doing the same make sure to add shadowDatabaseUrl = env("DATABASE_URL") line inside the datasource db block in schema file to run the migration successfully.
@AronGreenspan
@AronGreenspan Жыл бұрын
Thank you for this!
@Felipe-53
@Felipe-53 Жыл бұрын
Nice stuff, thanks!
@nathalianobrega6917
@nathalianobrega6917 Жыл бұрын
amazing video, learned a lot from this. keep up :)
@edbienes
@edbienes Жыл бұрын
wow, this is great content! thank you.
@deimiosxxx
@deimiosxxx Жыл бұрын
In case you want to group schemas in the docs, use "tags" key inside the routes. Just don't use multiple tags unless you want to duplicate the routes inside the docs. Example: schema: { body: $ref('createUserSchema'), response: { 201: $ref('createUserResponseSchema') }, tags: ['User'] }
@Marcos-zx6ey
@Marcos-zx6ey 2 жыл бұрын
I love this stack. Thank you for the video!
@TomDoesTech
@TomDoesTech 2 жыл бұрын
Thanks for watching!
@ayoubalfurjani4531
@ayoubalfurjani4531 Жыл бұрын
wonderful tutorial thanks
@vladcid3938
@vladcid3938 2 жыл бұрын
Thank you for this tutorial
@lutfiikbalmajid
@lutfiikbalmajid Жыл бұрын
Property 'jwtVerify' does not exist on type, why ya?
@myhanhnguyen5198
@myhanhnguyen5198 Жыл бұрын
at the time 1:09:22, where can you get the user? how can you assign user to the request before defining the module 'fastify-jwt'. I still don't understand how can you use request.user here on the line 12. Can you explain? Because request param has the type of FastifyRequest and it originally doesn't have user prop in it
@myron2454e
@myron2454e 2 күн бұрын
do you need to preregister typebox schemas? the creator of Fastify didnt do it in his video
@user-hm5ej5ke6j
@user-hm5ej5ke6j 2 жыл бұрын
Great video! Thank you!
@TomDoesTech
@TomDoesTech 2 жыл бұрын
Glad you liked it!
@giantkidney23
@giantkidney23 2 жыл бұрын
When I created zod schema, I customized some error messages for verification. But when I tried to verify, the custom error message didn't work.
@talkingtomcat8057
@talkingtomcat8057 11 ай бұрын
Same issue here
@samiullahsheikh5015
@samiullahsheikh5015 Жыл бұрын
Fastify support validation of JSON data via ajv JSON validator. so where does Zod fit in which is also a JSON validator?
@TomDoesTech
@TomDoesTech Жыл бұрын
Zod isn't a validator, it parses the data. You can use ajv if you like, I just wanted to use Zod
@samiullahsheikh5015
@samiullahsheikh5015 Жыл бұрын
@@TomDoesTech so what does it mean when a property in Json schema is set to required ? For example, in your zod schema it says the email field is required, it should be a string and an email
@donpardon
@donpardon Жыл бұрын
Hi Tom, great tutorial! It helped me a lot. One thing I cannot figure out though is that why the automatic type inference doesn't work in the route files. In my opinion it should know the type of request.body based on the schema. Can you help me with this?
@sakarsr
@sakarsr Жыл бұрын
Wonderful video. Thank you for your time showing the power of this framework. Is it possible to use decorated to use different databases for each user? A multitenant app where each user has his own database. In Prisma, we can change the database URL string at runtime. Any thoughts on it.
@TomDoesTech
@TomDoesTech Жыл бұрын
That's not a good approach to multitenancy imo, in fact it's not even really multitenant at that point, it's part of your app having different deployments. A much easier way to do it is separate all your data with an organization_id or application_id.
@ayonsharma8522
@ayonsharma8522 Жыл бұрын
Hey thanks for the tutorial, its awesome, but can you please tell me why server.authenticate was not avaiable in the Fastify instance even though we created a decorator for it and why did declaring a module make it worK? Thanks in advance
@npf21
@npf21 2 жыл бұрын
Nice done vid good to see a fellow aussie Curious would you of gone BigInt UTC for DateTime types so that the browser does not affect the timestamp? For prisma migrations is there a good package to use for implementing a field that can't be null? (for example if the API for stripe changes and you want to now insert a nonnull field pulling the data from stripe) or is it just easiest doing it manually with SQL then testing it locally with prisma migrate to see that it works?
@TomDoesTech
@TomDoesTech 2 жыл бұрын
Yeah dates should be stored in UTC. I'm not sure about non-null
@alex_rpascual
@alex_rpascual 2 жыл бұрын
There's only a postman enviroment file on the repo, not the collection.
@TomDoesTech
@TomDoesTech 2 жыл бұрын
I've added the colleciton
@NotAChannelll
@NotAChannelll Ай бұрын
Generic Type Error for FastifyReply and FastifyRequest After Installing fastify-jwt Types
@femzy1234
@femzy1234 7 ай бұрын
Nice tutorial, but I think the `preHandler` code to authenticate a route is old, doesn't seem be to working anymore
@Henzo17
@Henzo17 6 ай бұрын
On app.ts, on the line with server.decorate() check if you used 'auth' vs 'authenticate'.
@sainaththerala7645
@sainaththerala7645 2 жыл бұрын
I am seeing an issue while passing required accessToken from Swagger if possible please let me know how we can pass accessToken using swagger
@wykah
@wykah 2 жыл бұрын
I'm struggling with the resolution of the upload and can barely read what you've typed. I suspect it's the compression that's removed the sharpness.
@TomDoesTech
@TomDoesTech 2 жыл бұрын
The video is in 4k, try selecting the resolution manually and letting it load
@Gontran_
@Gontran_ 2 жыл бұрын
Thanks for the video but when I run the application after adding the product schema, I get an error : FastifyError: Schema with id 'Schema' already declared.
@TomDoesTech
@TomDoesTech 2 жыл бұрын
You need to give your schemas different names
@Gontran_
@Gontran_ 2 жыл бұрын
@@TomDoesTech Thanks, I solved it
@danielklein2694
@danielklein2694 2 жыл бұрын
@@TomDoesTech Hi I'm having same problem as Gontran, what exactly do you mean by giving schemas different name ?
@Buddhikasenevirathna
@Buddhikasenevirathna 2 жыл бұрын
@@TomDoesTech I am having same issue, where should we differentiate the Schema name
@Gontran_
@Gontran_ 2 жыл бұрын
​@@danielklein2694 @Buddhika senevirathna I solved the problem by adding to BuildJsonSchemas the id of the schema : { $id: 'UserSchema' } and { $id: 'ProductSchema' }
@HasanTezcan
@HasanTezcan 2 жыл бұрын
Can you add a additional part how we test this application
@TomDoesTech
@TomDoesTech 2 жыл бұрын
I'm working on it right now :) Should be out early next week!
@johnnydriesen7575
@johnnydriesen7575 2 жыл бұрын
@@TomDoesTech I'm interested as well. Please keep us informed. Thanks in advance for your time & effort. Really GREAT tuts !
@TomDoesTech
@TomDoesTech 2 жыл бұрын
@@johnnydriesen7575 Hey, I did a video where I tested this application kzbin.info/www/bejne/naKbi4Sod6-VaK8
@HasanTezcan
@HasanTezcan 2 жыл бұрын
@@TomDoesTech Thank you
@abhijeetshah6035
@abhijeetshah6035 Жыл бұрын
Thank you for the awesome tutorial. I am getting this runtime error when I run the tutorial. FastifyError [Error]: Failed building the validation schema for POST: /product, due to error can't resolve reference Schema#/properties/createProductSchema from id # . Not sure if the error is because I am using Mongodb or because of the wrong configuration. Going crazy trying to resolve it. Any help would be appreciated.
@TomDoesTech
@TomDoesTech Жыл бұрын
Need to make sure the schema id matches the registered schema
@donifadhila2265
@donifadhila2265 2 жыл бұрын
Hi, I followed everything in your code but my createUser always return error 500 even though the user is successfully created in the table... and I don't know why
@TomDoesTech
@TomDoesTech 2 жыл бұрын
I don't know either
@donifadhila2265
@donifadhila2265 2 жыл бұрын
@@TomDoesTech Hey I fixed it by moving the logic from user.service straight into the user.controller ... not sure why but it works now 😁
@pradiptapaul6630
@pradiptapaul6630 3 ай бұрын
Need a tutorial, fastify + typescript + mongodb(using mongoose)
@fernandes5389
@fernandes5389 Жыл бұрын
FastifyError: Missing schema $id property how to solve this error
@shmulyeng
@shmulyeng 8 ай бұрын
When creating the object that combines all the schemas, add an id export const { schemas: userSchemas, $ref } = buildJsonSchemas( { createUserSchema, createUserResponseSchema, loginSchema, loginResponseSchema, }, { $id: "userSchemas" } );
@lutfiikbalmajid
@lutfiikbalmajid Жыл бұрын
i am failed, but used npx tsc --init instead
@joepetrillo6185
@joepetrillo6185 Жыл бұрын
Is this tutorial still up to date?
@tlourammala
@tlourammala Жыл бұрын
I managed to update the necessary bits, let me know if you're keen. I can share you a repo.
@rohitv3955
@rohitv3955 Жыл бұрын
@@tlourammala Hi, I would like the updated repo please.
@АлМ-ы8ъ
@АлМ-ы8ъ 2 жыл бұрын
FastifyError: Schema with id 'Schema' already declared!
@TomDoesTech
@TomDoesTech 2 жыл бұрын
Check the pinned comment
@АлМ-ы8ъ
@АлМ-ы8ъ 2 жыл бұрын
@@TomDoesTech I was attempt changing the "$id" as "productSchemas[0]['$id'] = 'OtherSchema' but getting error that property readonly. However app begins working despite this issue
@АлМ-ы8ъ
@АлМ-ы8ъ 2 жыл бұрын
​@@TomDoesTech i reinstalled anyway fastify-zod to 0.0.2 ver
@t0ny404
@t0ny404 Ай бұрын
@@TomDoesTech Hey Tom, sorry to comment after 2 years but i don't see any pinned comments, do you remember how to fix this error?
@TomDoesTech
@TomDoesTech Ай бұрын
@@t0ny404 just looking at the error it looks.lkke you need to have a unique id for each schema
@kasirbarati3336
@kasirbarati3336 Жыл бұрын
Hi Tom Thanks for this gread crash course. I like your way of teaching. But I did not understand one part of your tut, where you said use 0.0.0.0 instead of localhost because Docker expect us to use it and it wont work otherwise. Would you like to share some link/ref/tut/video/anything about it with me. I am very keen.
@philipwilson6340
@philipwilson6340 Жыл бұрын
A truely fanstastic tutorial, love how you bring all the tools together so quickly. I followed all the way through fixing some of the deprecated module issues listed below, and the duplicate schema. Where I got stuck was at 1h13m where we resolve the 'request.user.id' being missing. As fastify-jwt is deprecated I moved to use @fastify/jwt instead and did the following declare: declare module '@fastify/jwt' { interface FastifyJwt { user: { id: number; email: string; name: string; }; } } however that did not resolve my missing id issue. on closer inspection I find that the IDE thinks the 'user' property is of type 'string', unfortunatley I'm strugging to understand how the 'user' property should be defined. I see the following definition in jwt.d.ts user: fastifyJwt.UserType export type UserType = FastifyJWT extends { user: infer T } ? T : SignPayloadType from that point on I was not able to get any of the products endpoints to work and got the following error response: { "statusCode": 500, "error": "Internal Server Error", "message": "Cannot read properties of undefined (reading 'product')" } but no uncaught exception on the server side debug output... any thoughts?
@ThiagoBussola
@ThiagoBussola 2 жыл бұрын
i tried your pinned answer but the error still persists plus i am not able to install this version of zod
@TomDoesTech
@TomDoesTech 2 жыл бұрын
Install a different version
Learn Just Enough Fastify to be Productive
29:47
TomDoesTech
Рет қаралды 20 М.
Fastify Course 🚀 The Performant Node.js Web Framework
36:30
哈莉奎因怎么变骷髅了#小丑 #shorts
00:19
好人小丑
Рет қаралды 44 МЛН
Minecraft Creeper Family is back! #minecraft #funny #memes
00:26
The Joker kisses Harley Quinn underwater!#Harley Quinn #joker
00:49
Harley Quinn with the Joker
Рет қаралды 50 МЛН
Build a Multi-Tenanted, Role-Based Access Control System
2:01:29
TomDoesTech
Рет қаралды 35 М.
Fastify Crash Course | Node.js Framework
39:43
Traversy Media
Рет қаралды 142 М.
Build a CRUD API with TypeScript, Express, MongoDB, Zod and Jest
1:38:56
Learn Express JS With TypeScript
40:16
TomDoesTech
Рет қаралды 74 М.
Why aren't you using Fastify? Or Koa? Or NestJS?
9:58
Maximilian Schwarzmüller
Рет қаралды 50 М.
Masterclass | Mastering Node.js Backends
1:58:52
Platformatic
Рет қаралды 22 М.
Learn tRPC In 45 Minutes
45:35
Web Dev Simplified
Рет қаралды 107 М.
哈莉奎因怎么变骷髅了#小丑 #shorts
00:19
好人小丑
Рет қаралды 44 МЛН