From 9fa0d57ce398eb6ae912415f748bc6c0c087bf65 Mon Sep 17 00:00:00 2001 From: Tien Do Nam Date: Fri, 16 Aug 2024 15:31:26 +0200 Subject: [PATCH] feat: add convenience method: `HttpTextResponse.bodyToJson` --- CHANGELOG.md | 4 ++++ lib/src/model/response.dart | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e758cc6..de3b8b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.1 + +- feat: add convenience method: `HttpTextResponse.bodyToJson` + ## 0.5.0 - feat: interceptors (e.g. `RetryInterceptor`) diff --git a/lib/src/model/response.dart b/lib/src/model/response.dart index 03945cc..3e442cb 100644 --- a/lib/src/model/response.dart +++ b/lib/src/model/response.dart @@ -1,3 +1,4 @@ +import 'dart:convert'; import 'dart:typed_data'; import 'package:meta/meta.dart'; @@ -33,6 +34,9 @@ class HttpTextResponse extends HttpResponse { required this.body, }); + /// Convenience method to parse the body as JSON. + dynamic get bodyToJson => jsonDecode(body); + @override String toString() { return 'HttpTextResponse(${version.name}, status: $statusCode)';