searchWikiData static method
Implementation
static Future<List<WikiDataSearchResult>> searchWikiData(
String query, {
http.Client? client,
}) async {
final result = <WikiDataSearchResult>[];
client ??= http.Client();
var response = await client.get(
Uri.parse(
'https://www.wikidata.org/w/api.php?'
'action=query'
'&'
'list=search'
'&'
'format=json'
'&'
'srsearch=$query',
),
);
if (response.statusCode == 200) {
for (final q in jsonDecode(response.body)["query"]["search"]) {
result.add(WikiDataSearchResult.fromJson(dj: q));
}
} else {
if (kDebugMode) {
print(response.statusCode);
print(response.reasonPhrase);
print(response.body);
}
}
return result;
}