Pakete, Repositories und App-Kategorien suchen

Paketdetailsv4.7.0

requests

eine Flutter-Bibliothek, die bei HTTP-Anfragen und gespeicherten Cookies hilft

AndroidiOSWebmacOSWindowsLinux
30-Tage-Downloads
3410
Likes
104
Pub-Punkte
130

Paket installieren

flutter pub add requests

Paketübersicht

Aus öffentlichen Paketdaten erstellte Orientierung.

Das requests-Paket ist eine Flutter-Bibliothek, die entwickelt wurde, um HTTP-Anfragen zu vereinfachen und gespeicherte Cookies über Plattformen hinweg zu verwalten. Es bietet eine intuitive API zum Ausführen von GET-, POST- und anderen HTTP-Methoden mit integrierter Unterstützung für Header, Abfrageparameter und Antwortverarbeitung. Die Bibliothek enthält automatische Cookie-Persistenz, was eine nahtlose Sitzungsverwaltung in webähnlichen Anwendungen ermöglicht. Sie ist mit Android, iOS, Web, macOS, Windows und Linux kompatibel und ideal für Apps, die zuverlässige Netzwerkkommunikation und zustandsbehaftete Interaktionen erfordern. Durch ihr leichtgewichtiges Design und die einfache Integration ist sie für Entwickler zugänglich, die effiziente HTTP-Operationen ohne Boilerplate-Code suchen.

Anwendungsfälle

  • Authentifizierte API-Aufrufe durchführen
  • Session-Cookies verwalten
  • Einfachere Integration von REST-APIs
  • Anforderungsheader und -payloads verwalten
  • Testen von Netzwerkendpunkten
  • Web-ähnliche App-Erfahrungen erstellen

Hauptmerkmale

  • Automatisches Speichern und Abrufen von Cookies
  • Unterstützung für alle wichtigen HTTP-Methoden
  • Plattformübergreifende Kompatibilität
  • Einfach zu verwendende synchrone und asynchrone APIs
  • Eingebaute Antwortanalyse-Tools
  • Konfigurierbare Anfragezeiten

Geeignet für

  • Entwickler, die Apps mit dauerhaften Sitzungen erstellen
  • Apps, die eine leistungsstarke HTTP-Client-Funktionalität erfordern
  • Projekte, die eine konsistente Cookie-Verwaltung erfordern
  • Teams, die minimale Einrichtung für HTTP-Anfragen wünschen
  • Prototyping oder schnelle Entwicklung von Netzwerkfunktionen

Hinweise

  • Erfordert sorgfältige Behandlung asynchroner Operationen
  • Für den Einsatz in der Produktion könnte zusätzliche Fehlerbehandlung erforderlich sein
  • Das Verhalten der Cookie-Speicherung kann sich je nach Plattform unterscheiden
  • Nicht geeignet für Hochleistungs- und Low-Latency-Szenarien
  • Eingeschränkte erweiterte Funktionen im Vergleich zu voll ausgestatteten Clients
  • Abhängig von externem GitHub-Repository für Updates

Original-README

Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.

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

Kategorien

Abhängigkeiten

Abhängigkeiten 4 Einträge

Quell-Repository

Projekte, die dieses Paket verwenden

Noch keine Daten verfügbar.