Run the following to setup cheetah:
When building a large API with cheetah, you probably want some sort of validation to reduce the amount of boilerplate code to validate the body, query, cookies, and header of the incoming request.
import cheetah from 'https://deno.land/x/cheetah/mod.ts'
import z from 'https://deno.land/x/zod/mod.ts'
const app = new cheetah()
app.post('/', {
body: z.object({
email: z.string().email(),
password: z.string()
})
}, () => 'Hello!')
cheetah ensures that neither parsing freezes your application nor a malformed request causes a crash.
import cheetah from 'https://deno.land/x/cheetah/mod.ts'
const app = new cheetah()
app.post('/', async (c) => {
const body = await c.req.buffer()
})
cheetah doesn't dictate you how to write your app. Chain it, nest it, have fun with it!
import cheetah from 'https://deno.land/x/cheetah/mod.ts'
const app = new cheetah()
.get('/cake', () => '🎂') // GET '/cake'
.patch('/cookie', () => '🍪') // PATCH '/cookie'
.put('/donut', () => '🍩') // PUT '/donut'
import cheetah, { Collection } from 'https://deno.land/x/cheetah/mod.ts'
const fastFood = new Collection()
.get('/burger', () => '🍔') // GET '/fast-food/burger'
const app = new cheetah()
.use('/fast-food', fastFood)
.patch('/pancakes', () => '🥞') // PATCH '/pancakes'
cheetah ranks among the fastest web frameworks for JavaScript and has a much shorter syntax compared to its competitors.
import cheetah from 'https://deno.land/x/cheetah@v1.5.0/mod.ts'
new cheetah()
.get('/', () => 'Hey!')
.serve()
import { Hono } from 'https://deno.land/x/hono@v3.5.5/mod.ts'
const app = new Hono()
.get('/', c => c.text('Hey!'))
Deno.serve(req => {
return app.fetch(req)
})
import { Application, Router } from 'https://deno.land/x/oak@v12.6.0/mod.ts'
const app = new Application()
const router = new Router()
.get('/', c => {
c.response.headers.set('content-type', 'text/plain; charset=utf-8')
c.response.body = 'Hey!'
})
app
.use(router.routes())
.use(router.allowedMethods())
.listen({ port: 8000 })