@POST("api/login")
Call<ApiResponse> loginUser(@Body String user);
Here the string is actually a JSONstring i.e.
{"email":"[email protected]","password":"test"}
Couldnt figure out what is wrong in this. Either the string it again converted to json. Please suggest..
This is what i want to do to my request as shown in picture.
This means your @GET or @DELETE should not have @Body parameter. You can use query type url or path type url or Query Map to fulfill your need. Else you can use other method annotation.
The Best Answer is The @Body annotation defines a single request body. Since Retrofit uses Gson by default, the FooRequest instances will be serialized as JSON as the sole body of the request. The Gson docs have much more on how object serialization works. And then use an instance of that class similar to #1.
Convert your data in object
public class Credentials
{
public String email;
public String password;
}
Set the data to object
Credentials loginCredentials = new Credentials();
loginCredentials.email = "[email protected]";
loginCredentials.password = "password";
Call your api
@POST("api/login")
Call<ApiResponse> loginUser(@Body Credentials credentials);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With