सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
requests पैकेज एक फ्लटर लाइब्रेरी है जिसका उद्देश्य HTTP रिक्वेस्ट को सरल बनाना और प्लेटफॉर्म के आसपास स्टोर्ड कुकीज का प्रबंधन करना है। यह एक उपयोगकर्ता-अनुकूल एपीआई प्रदान करता है जिसमें GET, POST और अन्य HTTP विधियों के लिए समर्थन होता है, जिसमें हेडर, क्वेरी पैरामीटर और प्रतिक्रिया हैंडलिंग के लिए निर्मित समर्थन शामिल है। लाइब्रेरी में स्वचालित कुकी स्थिरता शामिल है, जिससे वेब-जैसी एप्लिकेशन में बिना रुकावट के सत्र प्रबंधन संभव होता है। यह Android, iOS, वेब, macOS, Windows और Linux के साथ संगत है, जो विश्वसनीय नेटवर्क संचार और राज्य-आधारित इंटरैक्शन की आवश्यकता वाले एप्लिकेशन के लिए आदर्श है। इसका हल्का डिज़ाइन और सरल एकीकरण विकासकर्मियों के लिए बॉयलरप्लेट कोड के बिना कुशल HTTP ऑपरेशन के लिए उपलब्ध कराता है।
उपयोग
प्रमाणित API कॉल करना
सत्र कुकीज़ का प्रबंधन
REST API एकीकरण को सरल बनाना
अनुरोध हेडर और पेलोड का प्रबंधन करना
नेटवर्क एंडपॉइंट्स का परीक्षण करें
वेब-जैसे एप्लिकेशन अनुभव बनाना
मुख्य विशेषताएँ
स्वचालित कुकी संग्रहण और पुनर्प्राप्ति
सभी मुख्य HTTP विधियों का समर्थन
प्लेटफॉर्म के अनुकूलता
आसान उपयोग करने वाले सिंक्रोनस और एसिंक्रोनस API
एम्बेडेड रिस्पॉन्स पार्सिंग उपकरण
कॉन्फ़िगरेबल रिक्वेस्ट टाइमआउट
इनके लिए उपयुक्त
स्थायी सत्र के साथ ऐप बनाने वाले डेवलपर्स
मजबूत HTTP क्लाइंट कार्यक्षमता की आवश्यकता वाले ऐप्स
स्थिर कुकी प्रबंधन की आवश्यकता वाले परियोजनाएँ
HTTP रिक्वेस्ट के लिए न्यूनतम सेटअप चाहने वाली टीमें
नेटवर्क फीचर्स के प्रोटोटाइपिंग या त्वरित विकास
विचार योग्य बातें
असिंक ऑपरेशन का सावधानीपूर्वक निपटारा करने की आवश्यकता है
उत्पादन उपयोग के लिए अतिरिक्त त्रुटि संभावना की आवश्यकता हो सकती है
कुकी स्टोरेज व्यवहार प्लेटफॉर्म के आधार पर भिन्न हो सकता है
उच्च प्रदर्शन, कम देरी वाले परिदृश्यों के लिए उपयुक्त नहीं
पूर्ण-सुविधा वाले क्लाइंट्स की तुलना में सीमित उन्नत विशेषताएं
अपडेट के लिए बाहरी GitHub भंडार पर निर्भर करता है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
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 = awaitRequests.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 = awaitRequests.delete('https://reqres.in/api/users/10');
r.raiseForStatus();
Ignore SSL self-signed certificate
var r = awaitRequests.get('https://expired.badssl.com/', verify: false);
r.raiseForStatus();
Play with stored cookies
String url = "https://example.com";
awaitRequests.clearStoredCookies(url);
// Set cookies using [CookieJar.parseCookiesString]var cookies = CookieJar.parseCookiesString("name=value");
awaitRequests.setStoredCookies(url, cookies);
// Add single cookie using [CookieJar.parseCookiesString]var cookieJar = awaitRequests.getStoredCookies(url);
cookieJar["name"] = Cookie("name", "value");
awaitRequests.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");