No big news from me again — just enjoying the summer with my family and prepping some fresh content for you. In this issue, you'll find a handy Nuxt tip on validating data in your server routes. Hope you enjoy it!
👉🏻 Learn how to make a simple to-do app with Nuxt.
👉🏻 Instead of manually defining server routes and fetching them on the client, the author uses Prim+RPC to define functions on Nuxt's server and simply call those functions directly from the client.
👉🏻 Focus on building your product and not worry about setting up auth, database, infrastructure, payments, and more.
💡 Nuxt Tip: Validate Data in Your Server Routes
When you are working with Nuxt server routes, you should always validate the data that you receive from the client before processing it.
This is important to ensure that your application is secure and that you are not vulnerable to attacks such as SQL injection or cross-site scripting. Additionally, validating your data can help you catch errors early on and prevent them from causing issues later on in your application.
Luckily, h3 provides a simple and powerful way to validate data in your Nuxt server routes.
h3 is the H(TTP) server framework which is used by Nitro, which is the server engine used in Nuxt 3+.
It provides the following utility methods to help you validate your data:
getValidatedQuery to validate query parameters
getValidatedRouterParams to validate route parameters
readValidatedBody to validate the request body
h3 allows you to use the validation library of your choice like Zod, Yup, or Joi to validate your data.
For this example, we will use Zod to validate the data in our Nuxt server routes with the following schema:
1import { z } from 'zod';23const productSchema = z.object({4 name: z.string().min(3).max(20),5 id: z.number({ coerce: true }).positive().int(),6});
Let's see how we can use these validation utils to validate query parameters in our Nuxt server routes. Therefore, you can use the getValidatedQuery method provided by h3 instead of getQuery. This method takes the schema that you want to validate the query parameters against and returns the validated query parameters:
How's it going? I was planning to release the update for Reusable Components yesterday, but things haven't gone as planned. Instead, I will be launching it next week. I need a just a bit more time to make sure that the quality is up to my standards. As I've been updating the course and re-writing all the content and step-by-step refactorings, I've also been able to simplify a few things. It's just like refactoring a piece of code, and it's one of the greatest feelings. I also looked at how much content is in there, and it looks like it will be similar to the Clean Components Toolkit. Lots of great content on how to write highly reusable components, simplified and updated — I can't wait to release the update next week! Oh, and one more thing: I'm doing a podcast with Alex Lichter ! It's called Deja Vue and we'll be releasing the first ...
Tuesday, February 13, 2024 The News tab on the Scripting News home page was set up to request the All category from my FeedLand account. I switched to Tech, it's a bit faster, and probably a better fit. Still looking for a performance issue. # If you're thinking it might be good if President Biden stepped aside for someone younger and nicer to look at, what you really want is President Biden to be younger and nicer looking, and of course he probably wouldn't mind that either. But, as Keith Olbermann spells out so well in his latest Countdown , if he were to step aside that would basically concede the election to Trump. So if you think the old man is being silly and vain, well, he's being a lot smarter than you are, and btw, paying a huge price. If you live to be 81, I bet the last thing you want to do, after the life he's had, is to be in this position. We should get behind him, and tell him so, let him know we don't want anyone else, and we ...
评论
发表评论