Rest API

From the version 1.1.0 (yeah it should've been there since day 1 ...), you can now specify HTTP method which you want to listen to, directly in the route path in the Routes object.

/**@jsx h */
/**@jsxFrag Fragment */
import { serve } from 'https://deno.land/std/http/server.ts'
import { createHandler, json, h, Fragment } from 'https://deno.land/x/atlet@1.2.0/mod.ts'
import Post from 'legit-post'

const handler = await createHandler({
  'GET /post/:id': async (props) => json(await Post.findById(props.params.id)),
  'POST /post': async (props) => {
    const form = await props.request.formData()
    const newPost = await Post.create({
      text: form.get('text')?.toString() ?? '',
    })
    return json(newPost)
  },
  'DELETE /post/:id': (props) => {
    await Post.delete(props.params.id)
    return json({ ok: true })
  },
})

// you can also use Deno.serve which is available in Deno 1.35
serve(handler)