Repository
Current version released
4 years ago
Dependencies
std
jsweb
jsweb is a restiful json cors post method stateless super micro web framework based on node and deno.
switch node and deno is only one place to modify.
let app = new Application('deno'); // select deno
let app = new Application('node'); //select node
deno
- app.js
import { Application, Router,cors } from "https://deno.land/x/jsweb@v0.1.2/mod.js"; //remote
//import { Application, Router,cors } from "./mod.js"; //local
let app = new Application('deno');
let router = new Router();
app.use(async (ctx, next) => {
console.log(ctx.req.url);
await next();
});
app.use(cors);
//get test using http://127.0.0.1:5000/hello
router.get('/hello', function (ctx) {
let body = "<h1>Hello jsweb</h1>";
ctx.res.setHeader("Content-Type",'text/html');
ctx.res.body = body;
})
//get with params test using http://127.0.0.1:5000/test?name=jsweb
router.get('/test', function (ctx) {
let body = `<h1>Hello ${ctx.req.get.get('name')}</h1>`;
ctx.res.setHeader("Content-Type",'text/html');
ctx.res.body = body;
})
//post test using index.html in jsweb folder
router.post('/test', async (ctx) =>{
console.log(ctx.req.post);
ctx.res.setHeader("Content-Type",'application/json;charset=utf-8');
ctx.res.body = JSON.stringify(ctx.req.post);
})
app.use(router.routes());
app.listen('127.0.0.1', 5000);
deno run –allow-net app.js
node
import { Application, Router,cors } from "./mod.js"; //local
let app = new Application('node');
let router = new Router();
app.use(async (ctx, next) => {
console.log(ctx.req.url);
await next();
});
app.use(cors);
//get test using http://127.0.0.1:5000/hello
router.get('/hello', function (ctx) {
let body = "<h1>Hello jsweb</h1>";
ctx.res.setHeader("Content-Type",'text/html');
ctx.res.body = body;
})
//get with params test using http://127.0.0.1:5000/test?name=jsweb
router.get('/test', function (ctx) {
let body = `<h1>Hello ${ctx.req.get.get('name')}</h1>`;
ctx.res.setHeader("Content-Type",'text/html');
ctx.res.body = body;
})
//post test using index.html in jsweb folder
router.post('/test', async (ctx) =>{
console.log(ctx.req.post);
ctx.res.setHeader("Content-Type",'application/json;charset=utf-8');
ctx.res.body = JSON.stringify(ctx.req.post);
})
app.use(router.routes());
app.listen('127.0.0.1', 5000);
node app.js