Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send a List in a POST request #28

Closed
Zeswen opened this issue Apr 2, 2020 · 2 comments
Closed

Send a List in a POST request #28

Zeswen opened this issue Apr 2, 2020 · 2 comments
Assignees

Comments

@Zeswen
Copy link

Zeswen commented Apr 2, 2020

I need to post an object array ([{}, {}]) to my node.js server, something similar to this:

final List<Map<String, dynamic>> a = [
  {'a': 'b'}
];

final response = await Requests.post(
  API_URL,
  json: a,
  headers: HEADERS
);

However, the json parameter of the post method asks for Map<String, dynamic>, returning the following error:
The argument type 'List<Map<String, dynamic>>' can't be assigned to the parameter type 'Map<String, dynamic>'.

Any thoughts on this?
Thank you!

@jossef jossef self-assigned this Apr 13, 2020
@jossef
Copy link
Owner

jossef commented Apr 13, 2020

Thanks for reporting!
I'm thinking about changing the type from Map<String, dynamic> to dynamic

can you submit a PR?

@jossef jossef removed their assignment Apr 13, 2020
@jossef jossef self-assigned this May 23, 2020
@jossef jossef closed this as completed in 3a30c2b May 23, 2020
@jossef
Copy link
Owner

jossef commented May 23, 2020

fixed. this should now work:

var r = await Requests.post('https://example.com/api/v1/my-api', json: [{
   'userId': 10,
   'id': 91,
   'title': 'aut amet sed',
   'body':
   'libero voluptate eveniet aperiam sed\nsunt placeat suscipit molestias\nsimilique fugit nam natus\nexpedita consequatur consequatur dolores quia eos et placeat',
 }]);
r.raiseForStatus();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants