Dart
Installation
Add the Dart nekos_best
package to your project:
$ dart pub add nekos_best
Usage
Import the package to your project and use the methods.
import 'package:nekos_best/nekos_best.dart' show fetch, Client;
void main() async {
// Use the `fetch` function to fetch a random neko
var neko = await fetch(endpoint: 'neko');
print(neko);
// Alternatively you can initiate a `Client` class which
// provides more methods and functions
var client = Client();
// `Client.fetch` method
var baka = client.fetch(endpoint: 'baka');
// `Client.fetch` for a random category
var random = client.fetch();
// `Client.fetch` with an amount
var five_nekos = client.fetch(endpoint: 'baka', amount: 5);
// `Client.fetchFile` method
var kitsune_file = client.fetchFile('kitsune');
// `Client.search` method
var search = client.search('Gochuumon wa Usagi Desuka??');
}
The package uses NBResponse and NBBufferResponse classes in it's return values. You can access the fields with dot notation.
var baka = await client.fetch(endpoint: 'baka');
// It always returns a List<NBResponse>, so
// we need to get the first element from the list
print("url: ${baka[0].url}, source: ${baka[0].anime_name}");
See example/struct_example.dart for details and consult the Api Reference
More details on the package can be found in the repo's README. Examples on all methods, usage, classes are in the example directory.
Example without wrapper
Add http to your project and import it.
import 'package:http/http.dart' as http;
import 'dart:convert' as convert;
void main() async {
var url = Uri.parse('https://nekos.best/api/v2/neko');
var res = await http.get(url);
var neko = convert.jsonDecode(res.body) as Map<String, dynamic>;
print(neko['results'][0]);
}
About
Example added by: Yakiyo
Package source code is available on Github