Skip to content

impl mininum http server and client - #16

Merged
funlang merged 1 commit into
mainfrom
add-http-server
Oct 16, 2026
Merged

funlang merged 1 commit into
mainfrom
add-http-server

Conversation

@taadis

@taadis taadis commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Add: HTTP 服务端框架 http-server.fun + 客户端 http-client.fun,导入路径不带平台字样

在 Server.HTTP/HttpBase 之上做的内置 HTTP 框架:路由(:param/* 通配/405+Allow)、中间件(全局/组/路由、
洋葱模型、短路)、路由组、req/res、静态文件(含遍历防护)、访问日志。

调用示例

fun
// 服务端
use 'fun/lib/http-server.fun';
var s = HttpServer(8080); // 或 '0.0.0.0:8080';':8080' = 全网卡

fun hello(req, res) res.text('hello'); end fun;
s.get('/', hello);
s.get('/users/:id', user); // :param;另有 * 通配尾
s.Use(HttpLogger()); // 全局中间件

var api = s.group('/api'); // 路由组
api.Use(auth); // 组级中间件(不调 nx() 即短路)
api.get('/orders', orders);

s.static('/assets', './public');
s.run();

// 客户端
use 'fun/lib/http-client.fun';
var r = HttpClient([url: 'http://127.0.0.1:8080/users/42', method: 'GET']);
?. r.code; ?. r.body;

@funlang
funlang merged commit f2615c8 into main Oct 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants