搜索插件、代码仓与 APP 分类

插件详情v2.0.0-rc.6

relic_headers

HTTP 标头名称和由遗物适配器及其他包共享的存储。

近 30 天下载
1.9万
喜欢数
0
Pub 分数
160

安装插件

dart pub add relic_headers

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

relic_headers 包提供了一组标准化的 HTTP 头名称和存储工具,供 Relic 适配器及相关包使用。它确保了头处理的一致性,减少了错误并提高了 HTTP 客户端与服务器之间的互操作性。通过集中管理常用头信息,简化了网络通信工作流中的配置和维护。专为 ServerPod 生态系统设计,支持干净、可复用的 HTTP 交互代码。

适合场景

  • 跨服务标准化 HTTP 标头使用
  • 简化 HTTP 客户端中的请求头管理
  • 启用一致的 API 通信
  • 支持遗物适配器集成
  • 促进后端到后端的请求协调

主要特点

  • 集中式 HTTP 头定义
  • 用于存储请求头值的共享存储
  • 适配器之间的命名一致性
  • 轻量且依赖聚焦
  • 专为 ServerPod 生态系统设计

适合对象

  • 使用 ServerPod 或 Relic 适配器的开发者
  • 需要统一 HTTP 请求头处理的团队
  • 需要可靠 HTTP 客户端配置的项目
  • 后端服务通信
  • API 集成,带有统一的请求头

使用建议

  • 主要用于 ServerPod 项目中
  • 超出其生态系统范围的独立实用功能有限
  • 可能需要为非Relic工作流进行额外设置
  • 在没有上下文的情况下,不适用于通用 HTTP 库

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Relic web server banner

build codecov Stars on Github License: BSD-3-Clause

Relic web server

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 📚

Why Relic?

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:

  • Strongly typed APIs with validated HTTP headers.
  • Simplified interface for setting up routing and middleware.
  • Unified encoding model for HTTP bodies.
  • Built-in trie-based router, which improves performance.
  • Static file handling with support for cache busting and etags.
  • Built-in support for WebSockets.
  • Improvements in hot reload and running with multiple isolates.

Quick start

  1. Install Dart 3.7 or newer and verify with dart --version.
  2. Add Relic: dart pub add relic
  3. Create a new console app and drop in the hello world server below.
dart create -t console-full hello_world
cd hello_world
dart pub add relic
Run your first Relic server

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.

Additional examples

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

Migrating from Shelf

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.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。

所在榜单