You have web crypto at your disposal if you need to do things like hashing or encryption or decryption. And some other really cool features of Fresh which it sort of inherits from Deno are that there's no build step, which means you have really, really fast iteration times. You don't need any configuration. It all just works out of the box, no configuration necessary. And TypeScript also just works completely out of the box with no configuration necessary, just like it does in Deno.
Let's look at some code real quick, just to illustrate my point here. This is a very simple basic route, just like you would find it in probably most projects. To create a route, you put a TSX or JSX file into the routes folder in your project. In this case, I have a route called routes slash about.tsx, which due to the file system routing would be available at slash about on my web server. This is just a regular JSX component. It returns some HTLM markup, which is a server side rendered for each request. And that for each request is important, because if you have dynamic routes which contain parameters, for example, this route, greed slash name, you want to be able to change the output of your route depending on the input parameters. In this case, you want to read the specific user that requested that route.
And I think one of the most cool features of fresh is how it deals with interactive islands and how easy it makes it to take a static component and turn it into an interactive island. So to make a static component and turn it into an interactive island, the only thing you need to do in fresh is put it into the islands folder, there's a folder called islands, put a JSX component in there, you import that from your route, use it in your route, and fresh will do the rest. It'll make sure that it is sent to the client and hydrated there. It'll also make sure that anything which is static, for example, this route has a static title and paragraph, are not sent to the client as JavaScript. They're only sent to the client to static markup. And data fetching is also something that's very important nowadays and if you're doing server side rendering. This is inspired by Remix a lot. If you've used Remix before, you've used the data handlers and the fetch functions there, it's very familiar. You have a way to have a function that runs for each request, which you can do data fetching in and then pass some data to the page component or the route component rather, where that data is then rendered into some HTML. And you can even pass this data into the property of an island and it'll be serialized and hydrated all on the client automatically.
This was really fast. I'm sorry, we don't have a super large amount of time. If you want to get started yourself on Fresh, download the Deno CLI. You can do that from deno.and. Then you want to run this bootstrap command here, denovan-a-r https fresh.deno.dev, which also happens to be the Fresh home page. So if you want to learn more about Fresh, you can go there, specify a directory to generate a project, and enter that directory and run denotask start. And then you can view your new website at localhost 8000.
Comments