Skip to content

Instantly share code, notes, and snippets.

@jbergant
Created June 10, 2020 10:41
Show Gist options
  • Select an option

  • Save jbergant/a20f12ae67a323a32391a5bc208602fa to your computer and use it in GitHub Desktop.

Select an option

Save jbergant/a20f12ae67a323a32391a5bc208602fa to your computer and use it in GitHub Desktop.
Deno AOK simple demo
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
const app = new Application();
const router = new Router();
const PORT = 8000;
const HOST = "localhost";
export const getHome = ({ response }: { response: any }) => {
response.body = "Home page";
};
export const getContact = ({ response }: { response: any }) => {
response.body = "Contact page";
};
export const saveComment = async ({
request,
response,
}: {
request: any;
response: any;
}) => {
const body = await request.body();
// Do something with data
response.body = "Comment added";
response.status = 200;
};
router
.get("/", getHome)
.get("/contact", getContact)
.post("/addComment", saveComment);
app.use(router.routes());
app.use(router.allowedMethods());
console.log(`running on: ${HOST}:${PORT}`);
await app.listen(`${HOST}:${PORT}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment