'How to access Dart shelf post body parameters?

I am using Dart Shelf framework for building an API. Get works fine but I am having issues with post. I couldn't access any of the body parameters of the post request in my server. Here is what I have tried.

// shelf-router
router.post('/login', (Request req) async {
  final body = await req.readAsString();
// to check
 print(body); // outputs null
 return 
 Response.ok('OK');
});

How am I testing this?

Using postman with the endpoint and body type raw (JSON).

payload as

{
  "user":"testUser",
  "password":"p455w0rd"
}

I even tried setting contenttype header to application/JSON but no luck there too.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source