trevorwang / retrofit.dart

retrofit.dart is an dio client generator using source_gen and inspired by Chopper and Retrofit.
https://mings.in/retrofit.dart/
MIT License
1.05k stars 240 forks source link

Patch with RFC6902 #672

Closed Bikram-Shrestha closed 2 months ago

Bikram-Shrestha commented 2 months ago

Is your feature request related to a problem? Please describe. Currently there seems to be no way to make a patch request that take JsonPatch with content type application/json-patch+json

Describe the solution you'd like Implement RFC6902 Patch

import 'package:rfc_6901/rfc_6901.dart';
import 'package:rfc_6902/rfc_6902.dart'

class DevicePatchDTO{
.......
  JsonPatch toJsonPatch() =>
      JsonPatch.build([Replace(JsonPointer('/isPushEnabled'), isPushEnabled)]);
}

...........

class DeviceService{
......
  Future<void> makeRf6902Patch(
    DevicePatchDTO devicePatchDTO,
  ) async {
    await _dio.patchUri(
      Uri.https('example.org','/device'),
      options: Options(contentType: 'application/json-patch+json'),
      data: deviceRegistrationPatchDTO.toJsonPatch(),
    );
  }
}

I am not sure how to replicate this in retrofit and have found no documentation or way to implement this with retrofit.

Bikram-Shrestha commented 2 months ago

Managed to solve this by passing list of obj that has toJson() method that return Json obj instead of toJson method in JsonPatch which return List