Jaguar Dev Proxy 是一个用于开发环境的反向代理实现,旨在简化后端和 Web 服务器的工作流程。它使开发者能够在开发过程中无缝地在本地服务和外部端点之间路由请求。该工具基于 Dart 构建,是 Jaguar 生态系统的一部分,支持 Android、iOS、macOS、Windows 和 Linux 等多个平台。该包简化了本地环境中的 API 模拟、服务集成测试以及跨域通信。非常适合使用基于 Jaguar 的后端或需要轻量级代理且无需复杂配置的团队。
适合场景
本地 API 路由
开发环境代理
服务集成测试
API 模拟
跨源请求处理
主要特点
反向代理功能
多平台支持
轻量级设计
无缝开发工作流集成
内置的请求/响应操作
适合对象
后端开发人员
全栈式 Flutter 开发人员
DevOps 工程师
API 测试团队
Jaguar 框架用户
使用建议
不适用于生产环境
复杂的路由需要手动配置
与成熟的代理相比,文档有限
最适合仅用于开发的场景
依赖 Jaguar 生态系统
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Jaguar
Jaguar is a full-stack production ready HTTP server framework built to be fast, simple and intuitive.
Getting started
Familiar way to write routes
Jaguar class provides methods get, put, post,
delete and options to quickly add route handlers for specific HTTP methods.
main() async {
final server = Jaguar(); // Serves the API at localhost:8080 by default// Add a route handler for 'GET' method at path '/hello'
server.get('/hello', (Context ctx) => 'Hello world!');
await server.serve();
}
Powerful route matching
Easily define and access Path parameters
Path segments prefixed with : can match any value and are also captured as path variables. Path variables can be accessed
using pathParams member of Context object.
main(List<String> args) async {
final quotes = <String>[
'But man is not made for defeat. A man can be destroyed but not defeated.',
'When you reach the end of your rope, tie a knot in it and hang on.',
'Learning never exhausts the mind.',
];
final server = Jaguar();
server.get('/api/quote/:index', (ctx) { // The magic!finalint index = ctx.pathParams.getInt('index', 1); // The magic!return quotes[index + 1];
});
await server.serve();
}
A path can have multiple path variables.
A path variable can appear at any position in the path.
A path variable can be matched against a Regular expression.
getInt, getDouble, getNum and getBool methods can be used to easily typecast path variables.
Using * as the final path segment captures/matches all following segments.
Easily access Query parameters
Query parameters can be accessed using queryParams member of Context object.
main(List<String> args) async {
final quotes = <String>[
'But man is not made for defeat. A man can be destroyed but not defeated.',
'When you reach the end of your rope, tie a knot in it and hang on.',
'Learning never exhausts the mind.',
];
final server = Jaguar();
server.get('/api/quote', (ctx) {
finalint index = ctx.queryParams.getInt('index', 1); // The magic!return quotes[index + 1];
});
await server.serve();
}
getInt, getDouble, getNum and getBool methods can be used to easily typecast query parameters into desired type.
One liner to access Forms
A single line is all it takes to obtain a form as a Map<String, String> using method bodyAsUrlEncodedForm
on Request object.
The method staticFiles adds static files to Jaguar server. The first argument determines
the request Uri that much be matched and the second argument determines the directory from which the target files are fetched.
main() async {
final server = Jaguar();
server.staticFiles('/static/*', 'static'); // The magic!await server.serve();
}