'Dart Shelf Post Request No Body Data
I am building a simple API using Dart Shelf. The GET requests work fine but I can't seem to be able to access the request body for a POST request.
import 'dart:io' show InternetAddress;
import 'package:shelf/shelf.dart' show Request, Response;
import 'package:shelf/shelf_io.dart' show serve;
import 'package:shelf_router/shelf_router.dart' show Router;
void main() async {
Router router = Router();
router.get('/', (Request request) {
return Response.ok('this is the base URL');
});
router.post('/accounts', (Request request) async{
final body = await request.readAsString();
print(body);
return Response.ok(body);
});
final server = await serve(
router,
InternetAddress.anyIPv4,
8080,
);
print('Serving at http://${server.address.host}:${server.port}');
}
When I make the request I get the 200 OK status code but where is the body data?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
