Server
Integration & Deployment
Deno

Integration with Deno

Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 and is built in Rust (opens in a new tab). We will use fets which has an agnostic HTTP handler using Fetch API (opens in a new tab)'s Request (opens in a new tab) and Response (opens in a new tab) objects.

Example

Create a deno-fets.ts file:

deno-fets.ts
import { createRouter, Response } from 'https://cdn.skypack.dev/fets?dts'
import { serve } from 'https://deno.land/std@0.157.0/http/server.ts'
 
const router = createRouter().route({
  method: 'GET',
  path: '/greetings',
  schemas: {
    responses: {
      200: {
        type: 'object',
        properties: {
          message: {
            type: 'string'
          }
        },
        required: ['message'],
        additionalProperties: false
      }
    }
  } as const,
  handler: () => Response.json({ message: 'Hello World!' })
})
 
serve(router, {
  onListen({ hostname, port }) {
    console.log(`SwaggerUI -> http://${hostname}:${port}/docs`)
  }
})

And run it:

deno run --allow-net index.ts

You can also check a full example on our GitHub repository here (opens in a new tab)