https://github.com/tanay-pingalkar/pleasant
a pleasant simple http library for deno
https://github.com/tanay-pingalkar/pleasant
deno deno-module denoland http http-server
Last synced: 3 months ago
JSON representation
a pleasant simple http library for deno
- Host: GitHub
- URL: https://github.com/tanay-pingalkar/pleasant
- Owner: tanay-pingalkar
- Created: 2021-06-14T10:05:53.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-07-31T12:26:56.000Z (about 4 years ago)
- Last Synced: 2024-11-16T13:46:48.561Z (11 months ago)
- Topics: deno, deno-module, denoland, http, http-server
- Language: TypeScript
- Homepage: https://deno.land/x/pleasant@v0.0.1
- Size: 7.81 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pleasant
a pleasant http framework for deno## installation
``` javascript
import { Server } from "https://deno.land/x/pleasant@v0.0.1/lib/lib.ts";
```# usage
## get request
``` javascript
import { Server } from "https://deno.land/x/pleasant@v0.0.1/lib/lib.ts";const app = new Server(8080);
app.get("/", (_, res) => {
res.status(400).send("hello");
});app.up();
```## post request
```javascript
import { Server } from "https://deno.land/x/pleasant@v0.0.1/lib/lib.ts";const app = new Server(8080);
app.post("/", (req, res) => {
res.status(200).send(req.body);
});app.up();
```## sending file
``` javascript
import { Server } from "https://deno.land/x/pleasant@v0.0.1/lib/lib.ts";const app = new Server(8080);
app.get("/index", (req, res) => {
res.status(400).file("/index.html");
});app.up();
```
## serving static files
```javascript
import { Server } from "https://deno.land/x/pleasant@v0.0.1/lib/lib.ts";const app = new Server(8080);
app.static("/static");
app.up();
```## set headers
``` javascript
import { Server } from "https://deno.land/x/pleasant@v0.0.1/lib/lib.ts";const app = new Server(8080);
app.get("/index", (req, res) => {
res.header("header name","header value").status(400).file("/index.html");
});app.up();
```## params
``` javascript
app.get("/params",(req,res)=>{
res.status(200).send(req.params);
})
```
for `host/params?p1=123&p2=12`
return `{"p1":"123","p2":"12"}`