syumai / Dinatra
Licence: mit
Sinatra like light weight web app framework for deno.
Stars: ✭ 347
Programming Languages
typescript
32286 projects
Labels
Projects that are alternatives of or similar to Dinatra
caddy-esi
Middleware for Caddy Server integrating ESI (edge side includes) tags with parallel loading. Able to connect to HTTP/S/2, Memcache, Redis, shell scripts, gRPC and SQL backends 🐜🐜🐜
Stars: ✭ 28 (-91.93%)
Mutual labels: webserver
Ilruntime hotgames
基于ILRuntime的热更新能力实现的可以直接使用的框架,友情赠送C# WebService + WebSocketServer服务器端。
Stars: ✭ 293 (-15.56%)
Mutual labels: webserver
Plan
Player Analytics plugin for Minecraft Server platforms (Bukkit/Sponge/Nukkit/BungeeCord/Velocity) - View player activity of your server with ease. 📆
Stars: ✭ 322 (-7.2%)
Mutual labels: webserver
Odi
🌪🌌 Opinionated, Declarative, Idiomatic framework for building scalable, supportable and reliable enterprise applications.
Stars: ✭ 264 (-23.92%)
Mutual labels: webserver
Docker Webserver
WebServer (MariaDB, PHP-FPM, Nginx) composed from several separate containers linked together
Stars: ✭ 290 (-16.43%)
Mutual labels: webserver
picamera-motion
Raspberry Pi python PiCamera Lightweight Motion Detection. Includes easy curl script install/upgrade, whiptail admin menu system, single file web server and Rclone for uploading to a variety of web storage services.
Stars: ✭ 80 (-76.95%)
Mutual labels: webserver
Restana
Super fast and minimalist framework for building REST micro-services.
Stars: ✭ 341 (-1.73%)
Mutual labels: webserver
Cordova Httpd
Embed tiny web server into Cordova with a plugin
Stars: ✭ 271 (-21.9%)
Mutual labels: webserver
Jaguar
Jaguar, a server framework built for speed, simplicity and extensible. ORM, Session, Authentication & Authorization, OAuth
Stars: ✭ 286 (-17.58%)
Mutual labels: webserver
expross
Expross is a lightweight webserver to introduce JavaScript developers familiar with Express to Python.
Stars: ✭ 27 (-92.22%)
Mutual labels: webserver
Debian Server Tools
Tools and living docs 🧬 for Debian-based servers and Web Applications
Stars: ✭ 333 (-4.03%)
Mutual labels: webserver
Computer Networking A Top Down Approach Notes
《计算机网络-自顶向下方法(原书第6版)》编程作业,Wireshark实验文档的翻译和解答。
Stars: ✭ 3,890 (+1021.04%)
Mutual labels: webserver
Pode
Pode is a Cross-Platform PowerShell web framework for creating REST APIs, Web Sites, and TCP/SMTP servers
Stars: ✭ 329 (-5.19%)
Mutual labels: webserver
Saea
SAEA.Socket is a high-performance IOCP framework TCP based on dotnet standard 2.0; Src contains its application test scenarios, such as websocket,rpc, redis driver, MVC WebAPI, lightweight message server, ultra large file transmission, etc. SAEA.Socket是一个高性能IOCP框架的 TCP,基于dotnet standard 2.0;Src中含有其应用测试场景,例如websocket、rpc、redis驱动、MVC WebAPI、轻量级消息服务器、超大文件传输等
Stars: ✭ 318 (-8.36%)
Mutual labels: webserver
dinatra
- Sinatra like light weight web app framework for Deno.
- This app is using Deno Standard Modules.
- All features of this app are currently experimental.
Usage
example/index.ts
import {
app,
get,
post,
redirect,
contentType,
} from "https://denopkg.com/syumai/[email protected]/mod.ts";
app(
get("/hello", () => "hello"),
get("/hello/:id", ({ params }) => params.id),
get(
"/hello/:id/and/:name",
({ params }) => `:id is ${params.id}, :name is ${params.name}`,
),
get("/error", () => [500, "an error has occured"]),
get("/callName", ({ params }) => `Hi, ${params.name}!`),
post("/callName", ({ params }) => `Hi, ${params.name}!`),
get("/foo", () => redirect("/hello", 302)), // redirect from /foo to /hello
get("/info", () => [
200,
contentType("json"),
JSON.stringify({ app: "dinatra", version: "0.0.1" }),
]),
);
deno run --allow-net --allow-read index.ts # Or simply: deno run -A index.ts
# App runs on localhost:8080
curl http://localhost:8080/hello
# status: 200
# body: hello
curl http://localhost:8080/hello/1
# status: 200
# body: 1
curl http://localhost:8080/hello/1/and/John
# status: 200
# body: :id is 1, :name is John
curl http://localhost:8080/error
# status: 500
# body: an error has occured
curl http://localhost:8080/callName?name=John
# status: 200
# body: Hi, John!
curl -d 'name=Tom' http://localhost:8080/callName
# status: 200
# body: Hi, Tom!
curl http://localhost:8080/foo
# status: 302
# location: /hello
curl http://localhost:8080/info
# status: 200
# content-type: application/json
# body: {"app":"dinatra","version":"0.0.1"}
Async Handler
- You can use async function as handler.
const { cwd, open } = Deno;
import { app, get } from 'https://denopkg.com/syumai/dinatra/mod.ts';
const currentDir = cwd();
const htmlPath = `${currentDir}/index.html`;
app(get('/', async () => await open(htmlPath)));
Template
- You can use dejs (ejs for deno) as dinatra's template engine.
import { renderFile } from 'https://deno.land/x/dejs/dejs.ts';
app(
get('/', async () => await renderFile('index.ejs', { message: 'example' }))
);
Host static files
- Requires
--allow-read
, e.g.deno run --allow-read --allow-net app.ts
- Files in
./public
directory will be served static.
Close server
import { app, get } from 'https://denopkg.com/syumai/dinatra/mod.ts';
const s = app(get('/', () => 'hello'));
setTimeout(() => {
s.close(); // close server after 5s.
}, 5000);
Flags
deno run -A index.ts -p 8000 # or --port=8000
# App runs on localhost:8000
Initialization options
Customize static file hosting option
import { defaultPort } from 'https://denopkg.com/syumai/dinatra/constants.ts';
import { App, get } from 'https://denopkg.com/syumai/dinatra/mod.ts';
const app = new App(
defaultPort, // portNumber (number)
'dist', // public file directory's path (string)
false // option to enable static file hosting (boolean)
);
app.register(get('/hello', () => 'hello'));
Response Types
// HeaderMap is a type of response headers.
type HeaderMap =
| Headers
| {
[key: string]: any;
};
// ResponseBody is a type of response body.
type ResponseBody = string | ReadCloser | Deno.Reader;
/*
* Types of Response
*/
// StatusHeadersBodyResponse is a response with status code, headers, body.
type StatusHeadersBodyResponse = [number, HeaderMap, ResponseBody];
// StatusBodyResponse is a response with status code, body.
type StatusBodyResponse = [number, ResponseBody];
// Response is a type of response.
export type Response =
| StatusHeadersBodyResponse
| StatusBodyResponse
| number // HTTP status code only
| ResponseBody; // Response body only
// Response interface
interface HTTPResponse {
status?: number;
headers?: Headers;
body?: Uint8Array | Deno.ReadCloser | Deno.Reader;
}
Status
Request Params
- [x] URL query params (for GET)
- [x] route params (like:
/users/:user_id/posts
) - [x] x-www-form-urlencoded
- [x] redirect
- [x] application/json
- [ ] application/octet-stream
Development
Update module
- Please use dem
dem update https://deno.land/[email protected]
Lint
make lint
Format
make fmt
Testing
make test
Author
syumai
License
MIT
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].