Jaguar-dart/jaguar
Jaguar, a server framework built for speed, simplicity and extensible. ORM, Session, Authentication & Authorization, OAuth
前往 github 下載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!
final int 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
andgetBool
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) {
final int 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.
main(List<String> arguments) async {
final server = Jaguar(port: 8005);
server.postJson('/api/add', (ctx) async {
final Map<String, String> map = await ctx.req.bodyAsUrlEncodedForm(); // The magic!
contacts.add(Contact.create(map));
return contacts.map((ct) => ct.toMap).toList();
});
await server.serve();
}
One liner to serve static files
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();
}
JSON serialization with little effort
Decoding JSON requests can’t be simpler than using one of the built-in bodyAsJson
,
bodyAsJsonMap
or bodyAsJsonList
methods on
Request
object.
Future<void> main(List<String> args) async {
final server = Jaguar();
server.postJson('/api/book', (Context ctx) async {
// Decode request body as JSON Map
final Map<String, dynamic> json = await ctx.req.bodyAsJsonMap();
Book book = Book.fromMap(json);
return book; // Automatically encodes Book to JSON
});
await server.serve();
}
Out-of-the-box Sessions support
main() async {
final server = Jaguar();
server.get('/api/add/:item', (ctx) async {
final Session session = await ctx.req.session;
final String newItem = ctx.pathParams.item;
final List<String> items = (session['items'] ?? '').split(',');
// Add item to shopping cart stored on session
if (!items.contains(newItem)) {
items.add(newItem);
session['items'] = items.join(',');
}
return Response.redirect('/');
});
server.get('/api/remove/:item', (ctx) async {
final Session session = await ctx.req.session;
final String newItem = ctx.pathParams.item;
final List<String> items = (session['items'] ?? '').split(',');
// Remove item from shopping cart stored on session
if (items.contains(newItem)) {
items.remove(newItem);
session['items'] = items.join(',');
}
return Response.redirect('/');
});
await server.serve();
}
![](/images/banner-woo.jpg)
與 Jaguar-dart/jaguar 相關優秀專案推薦下載
localsend
33797
An open-source cross-platform alternative to AirDrop
gsy_github_app_flutter
14559
Flutter 超完整的开源项目,功能丰富,适合学习和日常使用。GSYGithubApp系列的优势:我们目前已经拥有Flutter、Weex、ReactNative、kotlin 四个版本。 功能齐全,项目框架内技术涉及面广,完成度高,持续维护,配套文章,适合全面学习,对比参考。跨平台的开源Github客户端App,更好的体验,更丰富的功能,旨在更好的日常管理和维护个人Github,提供更好更方便的驾车体验Σ( ̄。 ̄ノ)ノ。同款Weex版本 : https://github.com/CarGuo/GSYGithubAppWeex 、同款React Native版本 : https://github.com/CarGuo/GSYGithubApp 、原生 kotlin 版本 https://github.com/CarGuo/GSYGithubAppKotlin
dio
12249
A powerful HTTP client for Dart and Flutter, which supports global settings, Interceptors, FormData, aborting and canceling a request, files uploading and downloading, requests timeout, custom adapters, etc.
gopeed
11832
A modern download manager that supports all platforms. Built with Golang and Flutter.
bloc
11441
A predictable state management library that helps implement the BLoC design pattern
getx
9899
Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
flame
8846
A Flutter based game engine.
flutter_deer
7595
🦌 Flutter 练习项目(包括集成测试、可访问性测试)。内含完整UI设计图,更贴近真实项目的练习。Flutter practice project (including integration testing and accessibility testing). Contains complete UI design drawings for a more realistic practice project.
Flutter-Responsive-Admin-Panel-or-Dashboard
6355
Responsive Admin Panel or Dashboard using Flutter
riverpod
5828
A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
pikapika
5463
美观易用且无广告的漫画和游戏客户端,同时支持MacOS,Windows,Android,iOS。
provider
5029
InheritedWidgets, but simple
getwidget
4416
Most popular and easy to use open source UI library with 1000+ Widgets to build flutter app.
fvm
4325
Flutter Version Management: A simple CLI to manage Flutter SDK versions.
pilipala
4003
PiliPala 是使用Flutter开发的BiliBili第三方客户端,感谢使用。
flutter-webrtc
3970
WebRTC plugin for Flutter Mobile/Desktop/Web
flutter_screenutil
3787
Flutter screen adaptation, font adaptation, get screen information
flutter_rust_bridge
3608
Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
isar
3366
Extremely fast, easy to use, and fully async NoSQL database for Flutter
bruno
3126
An enterprise-class package of Flutter components for mobile applications. ( Bruno 是基于一整套设计体系的 Flutter 组件库。)