Jaguar-dart/client

Retrofit multipart form support

Closed this issue · 11 comments

Hey @tejainece what the plan for this, of course I want to try the lib and first call I need to implement (login) is in form data lol
Can you tell me the steps and I'll do a PR for this :)

Do we go for a @AsFormData annotation ?

Kleak commented

I think it should into the @GetReq and friend annotation

Hum strange as it's a post request not a get, that's why I was proposing AsMultipart like the AsJson already present

Kleak commented

That's right since it's a parameters it must be the same as @AsJson :)

Ok :) I'll dig into this then see if I'm able to make a PR thx

It might need changes to jaguar_serializer too, as for multipart we need Map<String, String> not Map<String, dynamic>, so jaguar_serializer should be able to serialize for multipart.
How does it sound ?

Kleak commented

that should not be a problem for jaguar_serializer
juste use a class like this :

class Multipart {
  String field;
  String field2;
  //..etc
}
Kleak commented

in the example of retrofit the user model is also a Map<String, String>

@jaumard @AsForm, @AsFormField, @AsMultipart, @AsMultipartField should be good.

jaguar_serializer can handle Map<String, String>.

@Kleak @tejainece the problem here is for example:

class User {
   int age;
  String name;
}

This will not cast to Map<String, String> but under a multipart data it will need to be. I was thinking to generate a toStringMap that will transform all fields to String automatically

My current code for the multipart support generate this:

Future<LoginResponse> login(LoginRequest request) async {
    var req = base.post.path("/login").multipart(serializers.to(request));
    return req.one(convert: serializers.oneFrom);
  }

but this code give me type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Map<String, String>'

@jaumard I have added url-encoded-form support c3ba261

But I have not fixed multipart form yet.