パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v4.7.0

requests

HTTPリクエストと保存されたCookieを扱うためのFlutterライブラリ

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
3410
いいね数
104
Pub ポイント
130

パッケージをインストール

flutter pub add requests

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

requests パッケージは、Flutter用のライブラリであり、HTTPリクエストを簡素化し、複数プラットフォーム間で保存されたクッキーを管理することを目的としています。GET、POST およびその他の HTTP メソッドの実行に向けた直感的な API を提供しており、ヘッダー、クエリパラメータ、レスポンス処理に対応する組み込み機能も備えています。自動クッキー永続化機能により、ウェブのようなアプリケーションにおけるシームレスなセッション管理が可能になります。Android、iOS、Web、macOS、Windows、Linux と互換性があり、信頼できるネットワーク通信と状態付きの相互作用を必要とするアプリに最適です。軽量な設計と簡単な統合により、ボイラープレートコードなしに効率的な HTTP 操作が実現できます。

用途

  • 認証されたAPI呼び出しを行う
  • セッションCookieの処理
  • REST API 統合の簡素化
  • リクエストヘッダーとペイロードの管理
  • ネットワークエンドポイントのテスト
  • ウェブのようなアプリ体験の構築

主な機能

  • 自動的なクッキーの保存と取得
  • すべての主要なHTTPメソッドをサポート
  • クロスプラットフォーム互換性
  • 使いやすい同期および非同期 API
  • 組み込みの応答解析ユーティリティ
  • 設定可能なリクエストタイムアウト

適している対象

  • 永続的なセッションを持つアプリを開発する開発者
  • 堅牢なHTTPクライアント機能を必要とするアプリ
  • 一貫したクッキー管理が必要なプロジェクト
  • HTTPリクエストの最小限のセットアップを望むチーム
  • ネットワーク機能のプロトタイピングまたは迅速な開発

注意事項

  • 非同期操作の取り扱いに注意が必要です
  • 本番環境での使用には、追加のエラー処理が必要になる場合があります
  • クッキーのストレージ動作は、プラットフォームによって異なる場合があります
  • 高性能で低遅延なシナリオには適していません
  • 機能豊富なクライアントと比べて、高度な機能が限定的です
  • 更新に外部のGitHubリポジトリに依存しています

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

banner-01

Version License

a dart library to make HTTP requests (inspired by python requests module). It comes with JSON support and a lightweight implementation to store cookies like a browser.

Cookies, huh?

Server side cookies (via response header SET-COOKIE) are stored using the assistance of quiver.cache. Stored cookies will be send seamlessly on the next http requests you make to the same domain (simple implementation, similar to a web browser).

Install

Add this to your package's pubspec.yaml file:

dependencies:
  requests: ^4.8.0-alpha.0

Usage

Start by importing the library

import 'package:requests/requests.dart';

Let's make a simple HTTP request

var r = await Requests.get('https://google.com');
r.raiseForStatus();
String body = r.content();
the Response object

just like in python's request module, the Response object has this functionality

  • r.throwForStatus() - will throw an exception if the response statusCode is not a great success.
  • r.raiseForStatus() - same as throwForStatus
  • r.statusCode - the response status code
  • r.url - the url in the request
  • r.headers - the response headers
  • r.success - a boolean. true indicates that the request was a great success
  • r.hasError - a boolean. true indicates that the request was not a great success
  • r.bytes() - return the body in the response as a list of bytes
  • r.content() - return the body in the response as a string
  • r.json() - recodes the body in the response and returns the result (dynamic type)
Optional Arguments
  • json - a dynamic object that will be json encoded and then be set as the request's body
  • body - a raw string to be used as the request's body
  • bodyEncoding - default RequestBodyEncoding.FormURLEncoded. will set the content-type header
  • headers - Map<String, String> of custom client headers to add in the request
  • timeoutSeconds - default 10 seconds. after that period of time without server response an exception is thrown
  • persistCookies - default true. if should respect server's command to persist cookie
  • verify - default true. if the SSL verification enabled
  • withCredentials - default false. for dart web to handle cookies, authorization headers, or TLS client certificates

Note: Only one optional argument can be used in a single request body or json

Class Methods
  • .clearStoredCookies(url) - clears the stored cookies for the url
  • .setStoredCookies(url, CookieJar) - set the stored cookies for the url
  • .getStoredCookies(url) - returns a CookieJar of the stored cookies for the url
  • .addCookie(url, name, value) - add a Cookie to the CookieJar associated to the url

Examples

HTTP post, body encoded as application/x-www-form-urlencoded, parse response as json

var r = await Requests.post(
  'https://reqres.in/api/users',
  body: {
    'userId': 10,
    'id': 91,
    'title': 'aut amet sed',
  },
  bodyEncoding: RequestBodyEncoding.FormURLEncoded);

r.raiseForStatus();
dynamic json = r.json();
print(json!['id']);

HTTP delete

var r = await Requests.delete('https://reqres.in/api/users/10');
r.raiseForStatus();

Ignore SSL self-signed certificate

var r = await Requests.get('https://expired.badssl.com/', verify: false);
r.raiseForStatus();

Play with stored cookies

String url = "https://example.com";
await Requests.clearStoredCookies(url);

// Set cookies using [CookieJar.parseCookiesString]
var cookies = CookieJar.parseCookiesString("name=value");
await Requests.setStoredCookies(url, cookies);

// Add single cookie using [CookieJar.parseCookiesString]
var cookieJar = await Requests.getStoredCookies(url);
cookieJar["name"] = Cookie("name", "value");
await Requests.setStoredCookies(url, cookieJar);

// Add a single cookie using [Requests.addCookie]
// Same as the above one but without exposing `cookies.dart`
Requests.addCookie(url, "name", "value");

More examples can be found in example/.

Business vector created by freepik - www.freepik.com

カテゴリー

依存関係

依存関係一覧 4 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。