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();
}