I have been trying to handle post request in aqueduct. After reading the documentation this is what I have been able to come up with channel.dart
router
.route("/chat")//"/chat/[:id]")
.link(() => ChatController());
chatController.dart
> import 'package:web_api/web_api.dart';
class ChatController extends ResourceController{
@Operation.get('id')
Future<Response> getProjectById(@Bind.path("id") int id) async {
// GET /chat/:id
print(id);
//return Response.ok({"key": "value"});
}
@Operation.post()
Future<Response> createChat(@Bind.body() Chat chat) async {
// POST /project
print("post");
final Map<String, dynamic> body = await request.body.decode();
final name =body['name'] as String;
print(" 1) name ==> $name");
//return Response.ok({"key": "value"});
}
}
class Chat extends Serializable{
int id;
String name;
@override
void readFromMap(Map<String, dynamic> map) {
id = map['id'] as int;
name = map['name'] as String;
}
@override
Map<String, dynamic> asMap() {
return {
'id': id,
'name': name
};
}
}
and finally html template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="http://127.0.0.1:8888/chat" method="POST">
<input id="id" name="id">
<input id="name" name="name">
<button type="submit">Submit</button>
</form>
</body>
</html>
the html template is not served by aquaduct. It's a different location all together. When I submit the form my console logs.
[INFO] aqueduct: Server aqueduct/2 started.
[INFO] aqueduct: POST /chat 15ms 415
why am I not seeing the body conents, how could I get to see the body (form values)