最后一个path元素是可选的,因此我创建了此匹配器
pathPrefix("the-endpoint" / Segment / Segment.?) { (left[String], right: Option[String]) => ... }
问题是,仅当我添加结尾的“ /”斜杠字符时,才会调用此路径:
即不要添加最后一个路径部分:
curl localhost:12345/the-endpoint/firstsegment
The requested resource could not be found
但是
curl localhost:12345/the-endpoint/firstsegment/
... all good , gets to the path as expected ...
答案 0 :(得分:0)
您可以使用ignoreTrailingSlash指令:
$all_city_names = array_column(json_decode($data->rajaongkir->results, true),
'city_name');
// Display all the city name(s)
var_dump($all_city_names);