From 6c4ee2579e45471c10890c2f1c3557d0e8d87da4 Mon Sep 17 00:00:00 2001 From: Daan Oolbekkink Date: Sat, 12 Oct 2024 17:10:38 +0200 Subject: [PATCH 1/2] Small adjustment for example in readme --- README.md | 59 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 83b963d..7574aeb 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ a dart library to make HTTP requests (inspired by python [requests](https://github.com/psf/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`](https://pub.dev/documentation/quiver/latest/quiver.cache/quiver.cache-library.html). Stored cookies will be send seamlessly on the next http requests you make to the same domain (simple implementation, similar to a web browser). +Server side cookies (via response header `SET-COOKIE`) are stored using the assistance of [`quiver.cache`](https://pub.dev/documentation/quiver/latest/quiver.cache/quiver.cache-library.html). 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 @@ -15,11 +15,13 @@ Add this to your package's pubspec.yaml file: ```yaml dependencies: - requests: ^4.8.0-alpha.0 + requests: ^4.8.0-alpha.0 ``` ## Usage + Start by importing the library + ```dart import 'package:requests/requests.dart'; ``` @@ -33,44 +35,43 @@ 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) +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` 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 +- `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` 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 +- `.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 ```dart @@ -104,7 +105,7 @@ Ignore SSL self-signed certificate ```dart var r = await Requests.get('https://expired.badssl.com/', verify: false); r.raiseForStatus(); -``` +``` --- @@ -125,7 +126,7 @@ 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"); +await Requests.addCookie(url, "name", "value"); ``` More examples can be found in [example/](./example/). From 796b26ca7e7260c5661d59f761918af5eb83754b Mon Sep 17 00:00:00 2001 From: Daan Oolbekkink Date: Sat, 12 Oct 2024 17:13:24 +0200 Subject: [PATCH 2/2] Revert unintended formatting --- README.md | 57 +++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 7574aeb..b9a3312 100644 --- a/README.md +++ b/README.md @@ -6,22 +6,20 @@ a dart library to make HTTP requests (inspired by python [requests](https://github.com/psf/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`](https://pub.dev/documentation/quiver/latest/quiver.cache/quiver.cache-library.html). 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: ```yaml dependencies: - requests: ^4.8.0-alpha.0 + requests: ^4.8.0-alpha.0 ``` ## Usage - Start by importing the library - ```dart import 'package:requests/requests.dart'; ``` @@ -35,43 +33,44 @@ 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) +- `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` 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 +- `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` 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 +- `.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 ```dart @@ -105,7 +104,7 @@ Ignore SSL self-signed certificate ```dart var r = await Requests.get('https://expired.badssl.com/', verify: false); r.raiseForStatus(); -``` +``` ---