패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.0.6

fluri

Fluri는 URI 수정을 쉽게 만들기 위해 설계된 유창한 URI 라이브러리입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
3만
좋아요
6
Pub 점수
140

패키지 설치

flutter pub add fluri

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

Fluri는 Dart 및 Flutter 애플리케이션에서 URI 조작을 간소화하기 위해 설계된 유창한 URI 라이브러리입니다. 직관적이고 체인 가능한 API를 제공하여 URI를 쉽게 생성하고 수정하며 파싱할 수 있습니다. 개발자는 깔끔하고 가독성 있는 코드를 유지하면서 경로, 쿼리 매개변수 및 프래그먼트를 원활하게 추가할 수 있습니다. Workiva가 개발한 Fluri는 Android, iOS, Web, macOS, Windows, Linux 등 모든 주요 플랫폼을 지원하며, 강력한 URL 처리 기능이 필요한 크로스플랫폼 프로젝트에 이상적입니다.

사용 사례

  • 동적 API 엔드포인트 구축
  • 런타임 시 URL 분석 및 수정
  • 복잡한 쿼리 문자열 구성
  • 상대 및 절대 URI 처리
  • 다양한 URL로 HTTP 클라이언트 테스트하기
  • 매개변수를 사용하여 탐색 경로 관리

주요 기능

  • 유연하고 체인 가능한 API
  • 쿼리 매개변수 변형 지원
  • 경로 및 조각 조작의 쉬움
  • 크로스 플랫폼 호환성
  • 불변 URI 생성
  • 강력한 구문 분석 및 직렬화

적합한 대상

  • 유연한 URI 처리가 필요한 플러터 개발자
  • 동적 엔드포인트 생성이 필요한 API 클라이언트
  • 복잡한 라우팅 또는 딥 링크를 가진 앱
  • 클린하고 유지보수 가능한 URL 로직을 우선시하는 팀
  • 다중 플랫폼 대상 프로젝트

고려 사항

  • 저수준 URL 분석을 위한 것이 아님
  • URI 구조 이해 필요
  • 간단한 정적 URL에 오버헤드를 추가할 수 있습니다
  • URI 전용 작업에 한정
  • dio 또는 http와 같은 HTTP 클라이언트와 함께 사용하는 것이 가장 좋습니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

fluri

Pub Build Status documentation

Examples/Usage

Fluri is a fluent URI library for Dart built to make URI mutation easy.

The dart:core.Uri class provides an immutable representation of URIs, which makes it difficult to incrementally build them or update them at a later time. If you wanted to build a long URI from the individual pieces, you would do something like this:

var uri = Uri(
  scheme: 'https',
  host: 'example.com',
  path: 'path/to/resource'
);

If you later wanted to update the path and add a query parameter, you'd have to do this:

uri = uri.replace(
  path: 'new/path',
  query: 'foo=true'
);

Now let's say you want update the query without losing what you already have:

var query = Map.from(uri.queryParameters);
query['bar'] = '10';
uri = uri.replace(queryParameters: query);

As you can see, incremental or fluent-style URI mutations become a hassle with the core Uri class.

With fluri, the above interactions are easy:

import 'package:fluri/fluri.dart';

var fluri = Fluri()
  ..scheme = 'https'
  ..host = 'example.com'
  ..path = 'path/to/resource';

fluri
  ..path = 'new/path'
  ..query = 'foo=true';

fluri.updateQuery({'bar': '10'});

Additional methods like appendToPath and setQueryParam make it easy to build on top of a base URL:

import 'package:fluri/fluri.dart';

var base = Fluri('https://example.com/base/');

var fluri = Fluri.from(base)
  ..appendToPath('path/to/resource')
  ..setQueryParam('count', '10');

Fluri also supports multi-value parameters. To access the query parameters as Map<String, List<String>>, use queryParametersAll (just like the Uri class):

var fluri = Fluri('/resource?format=json&format=text');
print(fluri.queryParameters); // {'format': 'text'}
print(fluri.queryParametersAll); // {'format': ['json', 'text']}

To set a single query parameter to multiple values:

var fluri = Fluri('/resource');
fluri.setQueryParam('format', ['json', 'text']);
print(fluri.queryParametersAll); // {'format': ['json', 'text']}

Using setQueryParam will always replace existing values:

var fluri = Fluri('/resource');
fluri.setQueryParam('format', ['json', 'text']);
fluri.setQueryParam('format', ['binary', 'text']);
print(fluri.queryParametersAll); // {'format': ['binary', 'text']}

You can use the queryParametersAll setter to set the entire query with multi-value param support:

var fluri = Fluri('/resource');
fluri.queryParametersAll = {'format': ['json', 'text'], 'count': ['5']}
print(fluri.queryParametersAll); // {'format': ['json', 'text'], 'count': ['5']}

Again, if you need to preserve existing query parameters, you can use the updateQuery method to do so. Set mergeValues: true and any values that you provide will be merged with existing values:

var fluri = Fluri('/resource?format=json');
fluri.updateQuery({'format': ['binary', 'text'], 'count': '5'}, mergeValues: true);
print(fluri.queryParametersAll); // {'format': ['binary', 'json', 'text'], 'count': ['5']}

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트