My flutter app sends the request to this API with the GET
method and uses the queryParameters
like this:
Map<String, dynamic> parameters = {'id': null};
parameters.updateAll((key, value) => Uri.encodeComponent(jsonEncode(value)));
String url= 'http://localhost:8080/test;
final Uri uri = Uri.parse(url).replace(queryParameters: parameters);
final http.Response response = await http.get(uri, headers: headers);
The URL
that was sent is http://localhost:8080/test?id=null
My route on the server side is:
final _route = shelf_router.Router()
..get("/test<id>", (Request request, String id) {
return Response.ok('ok');
})
..all('/<ignored|.*>', (Request request) {
return Response.notFound('notFound');
});
But my request from the flutter app always goes to the all('/<ignored|.*>', (Request request){ ... }
route.
I have tried to change the route name in the get("/test<id>", (Request request, String id){ ... }
from "/test<id>"
to "/test<id>"
, "/test?<id>"
, "/test?id<id>"
, or "/test?id=<id>"
but there isn't working.
What is the correct route name?
And I want to use the route with n parameters(get these parameters by using request.params[ ... ]
). What is the route name to do that?
OMG, I missed this. Just use the
"/test"
.The parameters are
request.url.queryParameters
example: