Repository
Current version released
4 years ago
Dependencies
std
Versions
- v1.3.4Latest
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.1
- v1.1.0
- v1.0.0
- v1.0.0-rc4
- v1.0.0-rc3
- v1.0.0-rc2
- v1.0.0-rc1
- v0.39.1
- v0.39.0
- v0.38.0
- v0.37.0
- v0.36.1
- v0.36.0
- v0.35.0
- v0.34.0
- v0.33.0
- v0.32.0
- v0.31.1
- v0.31.0
- v0.30.0
- v0.29.0
- v0.28.0
- v0.27.1
- v0.27.0
- v0.26.2
- v0.26.1
- v0.26.0
- v0.25.5
- v0.24.4
- v0.24.3
- v0.24.2
- v0.24.1
- v0.24.0
- v0.23.0
- v0.22.0
- v0.21.0
- v0.20.0
- v0.19.0
- v0.18.0
- v0.17.0
- v.0.17.0
- v0.16.0
- v0.15.0
- v0.14.0
- v0.13.0
- v0.12.1
- v0.12.0
- v0.11.0
- v0.10.1
- v0.10.0
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.1
- v0.8.0
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.0
- v0.5.0
- v0.4.0
- v0.3.1
- v0.3.0
- v0.2.1
- v0.2.0
- v0.1.1
- 1.0.0-rc1
servest
🌾A progressive http server / router for deno🌾
Usage
Serve API
serve
API is compatible with deno_std@v0.3.2 but has different implementation.
Some progressive features for HTTP/1.1 server are implemented.
- Support Keep-Alive connection
- Support trailer headers
- Support keep-alive timeout and read timeout
serve
is cancellable by cancel promise- Fully interface based type definition
import { serve } from "https://denopkg.com/keroxp/servest@v0.4.0/server.ts";
async function main() {
for await (const req of serve(`0.0.0.0:8899`)) {
await req.respond({
status: 200,
headers: new Headers({
"Content-Type": "text/plain"
}),
body: new TextEncoder().encode("hello")
});
}
}
main();
Router API
Router API is minimal routing system on top of serve()
import { createRouter } from "https://denopkg.com/keroxp/servest@v0.4.0/router.ts";
const router = createRouter();
router.handle("/", async req => {
await req.respond({
status: 200,
headers: new Headers({
"content-type": "text/plain"
}),
body: new TextEncoder().encode("ok")
});
});
router.handle(new RegExp("/foo/(?<id>.+)"), async req => {
const { id } = req.match.groups;
await req.respond({
status: 200,
headers: new Headers({
"content-type": "application/json"
}),
body: new TextEncoder().encode(JSON.stringify({ id }))
});
});
router.listen("127.0.0.1:8898");
Agent API
Agent API is basic HTTP agent. It manages persistent connection to host. Each request will be sent in serial.
NOTE: Currently TLS (HTTPS) agent is not supported as Deno doesn’t.
Use fetch
for https request.
GET
import { createAgent } from "https://denopkg.com/keroxp/servest@v0.5.0/agent.ts";
const agent = createAgent("http://127.0.0.1:8700");
const { status, body } = await agent.send("/get?deno=land");
POST
import { createAgent } from "https://denopkg.com/keroxp/servest@v0.5.0/agent.ts";
const { status, headers, body } = await agent.send("/post", {
method: "POST",
headers: new Headers({
"Content-Type": "text/plain"
}),
body: new TextEncoder().encode("deno=land")
});
Loadmaps
- Middleware API for Router
- HTTP/2
License
MIT