flutter http json with cookies
a flutter library to do modern http requests with cookies(inspired by python's requests module).
server side cookies (via response header SET-COOKIE
) are stored using the assistance of shared_preferences
. Stored cookies will be send seemlessly 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: ^1.0.0
Usage
in your Dart code, you can use:
import 'package:requests/requests.dart';
HTTP get, body as plain text
String body = await Requests.get("https://mydomain.com");
HTTP get, body as parsed json
dynamic body = await Requests.get("https://mydomain.com/api/v1/foo", json: true);
HTTP post, body is json, result is json
dynamic body = await Requests.post("https://mydomain.com/api/v1/foo", json: true, body: {"foo":"bar"} );
HTTP delete
await Requests.delete("https://mydomain.com/api/v1/foo/123");
Libraries
Dart
- dart:ui
- Built-in types and core primitives for a Flutter application. [...]
- dart:async
- Support for asynchronous programming, with classes such as Future and Stream. [...]
- dart:collection
- Classes and utilities that supplement the collection support in dart:core. [...]
- dart:convert
- Encoders and decoders for converting between different data representations, including JSON and UTF-8. [...]
- dart:core
- Built-in types, collections, and other core functionality for every Dart program. [...]
- dart:developer
- Interact with developer tools such as the debugger and inspector. [...]
- dart:math
- Mathematical constants and functions, plus a random number generator. [...]
- dart:typed_data
- Lists that efficiently handle fixed sized data (for example, unsigned 8 byte integers) and SIMD numeric types. [...]
- dart:io
- File, socket, HTTP, and other I/O support for non-web applications. [...]
- dart:isolate
- Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]