Riley Fitzpatrick
Riley Fitzpatrick

Reputation: 919

Flutter http.post() post user data

I am using Flutter to post to a url in our REST api. Most of the data is sent in the body and the params, which I am familiar with. However, the api attempts to get user data by calling req.user.email. My issue is that I do not know how to post data that is not in the body. My code is:

lang-dart

    var response = await http.post(
      url,
      body: {
        "text": answer,
      },
    );

How can I incorporate user data? The user is already logged in through Firebase and I am storing the user in a custom model with all user data. Hope this isn't too obvious, I am pretty new to REST APIs.

Upvotes: 0

Views: 177

Answers (1)

Lucas Lima da Silva
Lucas Lima da Silva

Reputation: 118

Like @Blasanka said, you should implement add a user object to your POST and it should have an e-mail. Maybe it should be cool to add a toJson method to your user class.

This code, added by @Blasanka, should do the trick

body: {
  "text": answer,
  "user": user.toJson(firebaseUser)
}

Upvotes: 1

Related Questions