CS 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' as nb;

void main() async {
    var neko = await nb.fetch(endpoint: 'neko');
    print(neko);
}

The package only exports a single function fetch

var random = nb.fetch();
var single_neko = nb.fetch(endpoint: 'neko');
var multi_neko = nb.fetch(endpoint: 'neko', amount: 5);

You can specify the amount of results you want, or the category from which to get the result. Both are optional. By default, amount is set to 1. If the endpoint is unspecified, it uses a randomly chosen endpoint.

The function returns a list of class NBResponse. You can access it's fields with dot notation.

var baka = await nb.fetch(endpoint: 'baka');
// It always returns a list of NBResponse, so 
// we need to get the first element from the list
print("url: ${baka[0].url}, source: ${baka[0].anime_name}");

More details on the package can be found in the repo's README. The example is 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

NekosBest NekosBest NekosBest