搜尋套件、儲存庫與 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.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。

所在榜單