relic
Shelf를 참고로 한 가볍고 유연한 웹 서버로, API 및 백엔드 서비스를 구축하는 데 사용됩니다.
Shelf를 영감으로 삼은 고성능 웹 서버 프레임워크입니다. Relic은 확장 가능한 웹 서비스를 구축하기 위한 강력하고 타입 안전하며 효율적인 기반을 제공합니다.
8.8.0아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Relic web server banner
build codecov Stars on Github License: BSD-3-Clause
Relic is a modern, high-performance web server framework inspired by Shelf and built by the Serverpod team to meet the demanding requirements of modern web applications. Relic provides a robust, type-safe, and efficient foundation for building scalable web services.
👉 Full documentation available here 📚
While Shelf has been a solid foundation for Dart web applications, several areas for improvement were identified. Rather than work around these limitations, Relic was created as a next-generation framework that maintains Shelf's familiar structure while delivering significant enhancements. These are some of the improvements:
dart --version.dart pub add relicdart create -t console-full hello_world
cd hello_world
dart pub add relic
Place this file in bin/hello_world.dart (runnable example is also under example/example.dart):
import 'package:relic/io_adapter.dart';
import 'package:relic/relic.dart';
/// A simple 'Hello World' server demonstrating basic Relic usage.
Future<void> main() async {
// Setup the app.
final app =
RelicApp()
// Route with parameters (:name & :age).
..get('/user/:name/age/:age', helloHandler)
// Middleware on all paths below '/'.
..use('/', logRequests())
// Custom fallback - optional (default is 404 Not Found).
..fallback = respondWith(
(_) => Response.notFound(
body: Body.fromString("Sorry, that doesn't compute.\n"),
),
);
// Start the server (defaults to using port 8080).
await app.serve();
}
const _ageParam = PathParam<int>(#age, int.parse);
/// Handles requests to the hello endpoint with path parameters.
Response helloHandler(final Request req) {
final name = req.pathParameters.raw[#name];
final age = req.pathParameters.get(_ageParam);
return Response.ok(
body: Body.fromString('Hello, $name! To think you are $age years old.\n'),
);
}
Run it with dart run bin/hello_world.dart and visit http://localhost:8080/user/Nova/age/27.
Relic comes with an extensive set of examples. To run them, clone the Relic repository from GitHub and navigate to the example directory.
git clone https://github.com/serverpod/relic.git
cd relic/example
dart example.dart
Are you on Shelf? Moving over is straightforward. Relic's APIs are very similar while giving you typed requests, built-in routing, and WebSockets out of the box. Follow the step-by-step guide at docs.dartrelic.dev/getting-started/shelf-migration to upgrade your project in minutes.