Repository navigation
impl mininum http server and client - #16
Merged
Merged
Conversation
funlang
approved these changes
Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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;