Repository
Current version released
4 years ago
Dependencies
std
railgun
deno web server framework
available features:
- middlewares
- context
- router
usage
import { Application } from 'https://deno.land/x/railgun/mod.ts';
const app = new Application();
await app.listen({ port: 3000 });
example
import { Application, Router, Status, MediaType, CONTENT_TYPE } from 'https://deno.land/x/railgun/mod.ts';
const app = new Application();
const router = new Router();
await app
.use(async (ctx, next) => {
const start = Date.now();
await next();
console.log(`${ctx.method} ${ctx.url} - ${Date.now() - start}ms`);
})
.use(
router
.get('/meow/(?<catName>.+)', (ctx, { catName }) => {
ctx.body = `my name is ${decodeURIComponent(catName)}, meow! π±`;
})
.post('/teapot', (ctx) => {
ctx.status = Status.Teapot;
})
.all('/', (ctx) => {
ctx.set(CONTENT_TYPE, MediaType.HTML);
ctx.body = `<html>
<head>
<title>hello</title>
</head>
<body>
<div>hello!</div>
</body>
</html>
`;
})
.routes()
)
.listen({ port: 3000 }, () => {
console.log(`starts listening :3000`);
});