{"id":28390791,"url":"https://github.com/flutterchina/cookie_jar","last_synced_at":"2025-06-28T08:31:43.816Z","repository":{"id":45296655,"uuid":"131127465","full_name":"flutterchina/cookie_jar","owner":"flutterchina","description":"A cookie manager for http requests in Dart, by which you can deal with the complex cookie policy and persist cookies easily.","archived":false,"fork":false,"pushed_at":"2024-07-08T20:48:56.000Z","size":105,"stargazers_count":400,"open_issues_count":8,"forks_count":76,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-06-06T16:20:04.686Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flutterchina.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["https://paypal.me/wendux91","https://camo.githubusercontent.com/3442fb56bdedc11300c23d958a2f62e813adae4903bd714fe852232623bb97c6/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f666c75747465726368696e612f666c75747465722d696e2d616374696f6e40312e302e332f646f63732f696d67732f7061792e6a706567"],"github":"AlexV525"}},"created_at":"2018-04-26T08:50:26.000Z","updated_at":"2025-05-29T00:47:05.000Z","dependencies_parsed_at":"2024-06-18T12:39:10.001Z","dependency_job_id":"2c66fb1b-441e-4b99-aeb1-40b06626a89a","html_url":"https://github.com/flutterchina/cookie_jar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flutterchina%2Fcookie_jar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flutterchina%2Fcookie_jar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flutterchina%2Fcookie_jar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flutterchina%2Fcookie_jar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flutterchina","download_url":"https://codeload.github.com/flutterchina/cookie_jar/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flutterchina%2Fcookie_jar/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258521983,"owners_count":22714442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-31T06:12:30.120Z","updated_at":"2025-06-28T08:31:43.810Z","avatar_url":"https://github.com/flutterchina.png","language":"Dart","funding_links":["https://paypal.me/wendux91","https://camo.githubusercontent.com/3442fb56bdedc11300c23d958a2f62e813adae4903bd714fe852232623bb97c6/68747470733a2f2f63646e2e6a7364656c6976722e6e65742f67682f666c75747465726368696e612f666c75747465722d696e2d616374696f6e40312e302e332f646f63732f696d67732f7061792e6a706567","https://github.com/sponsors/AlexV525"],"categories":[],"sub_categories":[],"readme":"# CookieJar\n\n[![Pub](https://img.shields.io/pub/v/cookie_jar.svg?style=flat-square)](https://pub.dev/packages/cookie_jar)\n[![GitHub license](https://img.shields.io/github/license/flutterchina/cookie_jar)](https://github.com/flutterchina/cookie_jar/blob/main/LICENSE)\n\nA cookie manager for http requests in Dart, help you to deal with the cookie policies and persistence.\n\n## Get started\n\n\u003e Checkout the [Migration Guide](migration_guide.md) for breaking changes between versions.\n\n### Add dependency\n\nYou can use the command to add dio as a dependency with the latest stable version:\n\n```console\n$ dart pub add cookie_jar\n```\n\nOr you can manually add cookie_jar into the dependencies section in your pubspec.yaml:\n\n```yaml\ndependencies:\n  cookie_jar: ^replace-with-latest-version\n```\n\nThe latest version is: ![Pub](https://img.shields.io/pub/v/cookie_jar.svg)\nThe latest version including pre-releases is: ![Pub](https://img.shields.io/pub/v/cookie_jar?include_prereleases)\n\n## Usage\n\nA simple usage example:\n\n```dart\nimport 'package:cookie_jar/cookie_jar.dart';\n\nvoid main() async {\n  final cookieJar = CookieJar();\n  List\u003cCookie\u003e cookies = [Cookie('name', 'wendux'), Cookie('location', 'china')];\n  // Saving cookies.\n  await cookieJar.saveFromResponse(Uri.parse('https://pub.dev/'), cookies);\n  // Obtain cookies.\n  List\u003cCookie\u003e results = await cookieJar.loadForRequest(Uri.parse('https://pub.dev/paths'));\n  print(results);\n}\n```\n\n## Classes\n\n### `SerializableCookie`\n\nThis class is a wrapper for `Cookie` class.\nBecause the `Cookie` class doesn't support Json serialization,\nfor the sake of persistence, we use this class instead of it.\n\n### `CookieJar`\n\n`CookieJar` is a cookie container and manager for HTTP requests.\n\n#### `DefaultCookieJar`\n\n`DefaultCookieJar` is a default cookie manager which implements the standard cookie policy declared in RFC.\nIt saves the cookies in the memory, all cookies will be cleared after the app exited.\n\nTo use it:\n\n```dart\n\nfinal cookieJar = CookieJar();\n```\n\n### `PersistCookieJar`\n\n`PersistCookieJar` is a cookie manager which implements the standard cookie policy declared in RFC.\n`PersistCookieJar` persists the cookies in files,\nso if the application exit, the cookies always exist unless call `delete` explicitly.\n\nTo use it:\n\n```dart\n// Cookie files will be saved in files in \"./cookies/4/\"\nfinal cookieJar = PersistCookieJar(\n  ignoreExpires: true, // Save/load even cookies that have expired.\n);\n```\n\n\u003e **Note**: When using the [FileStorage] in Flutter apps,\n\u003e use [path_provider](https://pub.dev/packages/path_provider) to obtain available directories.\n\n```dart\n\nDirectory tempDir = await\n\ngetTemporaryDirectory();\n\nfinal tempPath = tempDir.path;\nfinal cookieJar = PersistCookieJar(\n  ignoreExpires: true,\n  storage: FileStorage(tempPath),\n);\n```\n\n#### Storage\n\nYou can customize your own storage by extending `Storage`, see `FileStorage` for more details.\n\n## APIs\n\n**Future\u003cvoid\u003e saveFromResponse(Uri uri, List\u003cCookie\u003e cookies);**\n\nSave the cookies for specified uri.\n\n**Future\u003cList\u003cCookie\u003e\u003e loadForRequest(Uri uri);**\n\nLoad the cookies for specified uri.\n\n**Future\u003cvoid\u003e delete(Uri uri, [bool withDomainSharedCookie = false])**\n\nDelete cookies for specified `uri`.\nThis API will delete all cookies for the `uri.host`,\nit will ignore the `uri.path`.\n\nIf `withDomainSharedCookie` is `true `,\nall domain-shared cookies will be deleted.\n\n**Future\u003cvoid\u003e deleteAll();**\n\nDelete all cookies.\n\n## Working with `HttpClient`\n\nUsing `CookieJar` or `PersistCookieJar` manages\n`HttpClient `'s request/response cookies is quite easy:\n\n```dart\nfinal cookieJar = CookieJar();\nrequest = await httpClient.openUrl(options.method, uri);\nrequest.cookies.addAll(await cj.loadForRequest(uri));\nresponse = await request.close();\nawait cookieJar.saveFromResponse(uri, response.cookies);\n```\n\n## Working with dio\n\n[dio](https://github.com/cfug/dio) is a powerful HTTP client for Dart/Flutter,\nwhich supports global configuration, interceptors, FormData, request cancellation,\nfile uploading/downloading, timeout, and custom adapters etc.\ndio also supports to manage cookies with `cookie_jar`\nusing [dio_cookie_manager](https://pub.dev/packages/dio_cookie_manager).\nFor example:\n\n```dart\nimport 'package:dio/dio.dart';\nimport 'package:dio_cookie_manager/dio_cookie_manager.dart';\nimport 'package:cookie_jar/cookie_jar.dart';\n\nvoid main() async {\n  final dio = Dio();\n  final cookieJar = CookieJar();\n  dio.interceptors.add(CookieManager(cookieJar));\n  await dio.get('https://pub.dev/');\n  // Print cookies\n  print(await cookieJar.loadForRequest(Uri.parse('https://pub.dev/')));\n  // Another request with the cookie.\n  await dio.get(\"https://pub.dev/\");\n}\n```\n\nMore details about [dio](https://github.com/flutterchina/dio).\n\n## Copyright \u0026 License\n\nThe project and it's underlying projects\nare originally authored by\n[@wendux](https://github.com/wendux)\nwith the organization\n[@flutterchina](https://github.com/flutterchina)\nsince 2018.\n\nThe project consents [the MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflutterchina%2Fcookie_jar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflutterchina%2Fcookie_jar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflutterchina%2Fcookie_jar/lists"}