Intro
Out of the box, Atlet allows you to:
- Use JSX
- Write async components, since everything is SSR only
- Use all your favorite Tailwind classes (thanks to UnoCSS)
- Write standard REST API endpoints
Other great advantage is that you can write your Atlet web application, and you can easily deploy it on Deno Deploy.
Getting started
To begin a project with Atlet, import the createHandler function from the TODO.
import { createHandler } from 'https://deno.land/x/atlet@1.2.0/mod.ts'To properly use JSX, you have to add this pragma comment at the begininng of the file to tell Deno, which rendering function to use. There is certainly a better way to make this library in such a way, that this won't be needed. But not right now.
/**@jsx h */
/**@jsxFrag Fragment */
import { createHandler, h, Fragment } from 'https://deno.land/x/atlet@1.2.0/mod.ts'Okay, let's actually write something.
/**@jsx h */
/**@jsxFrag Fragment */
import { serve } from 'https://deno.land/std/http/server.ts'
import { createHandler, Props, h, Fragment } from 'https://deno.land/x/atlet@1.2.0/mod.ts'
const handler = await createHandler({
'/': (props: Props) => (
<h1>Hello from {props.url.hostname}</h1>
)
})
// you can also use Deno.serve which is available in Deno 1.35
serve(handler)Now to start this web application use command deno run --allow-read --allow-net main.tsx.
Flag --allow-read is needed for the static asset handling.
Right now, we just made a very basic website which will return a heading text with the current path. Let's check some other ways you can write endpoints.