Usage
First create file my_app.ts
and copy in the code from the example above.
import { NHttp } from "https://deno.land/x/nhttp@1.1.11/mod.ts";
const app = new NHttp();
app.get("/", (rev) => { return rev.response.send('hello');});
// or directlyapp.get("/hello", () => { return "Hello";});app.get("/hello-json", () => { return { name: "nhttp" };});
// Regexpapp.get(/hello/, () => { return "hello";});
app.listen(3000, () => { console.log("> Running on port 3000");});
#
RunningNow, run the file my_app.ts
.
deno run --allow-net my_app.ts
Example sending json.
...app.get("/json", ({ response }) => { return response.json({ name: 'nhttp' });});....
Example using POST method.
...app.post("/save", ({ response, body }) => { return response.json(body);});...
Example return directly.
...app.get("/", () => { return "hello";});app.get("/json", () => { return { name: "john" };});app.get("/nhttp", () => { return new Response("nhttp");});....