dynamic_call 2.0.1 copy "dynamic_call: ^2.0.1" to clipboard
dynamic_call: ^2.0.1 copied to clipboard

Dynamic Call framework, including API calls integrations (HTTP, RESTful).

example/example.dart

import 'package:dynamic_call/dynamic_call.dart';

class Sys {
  /// Defines a call with input field `query`, output as `STRING` and allows
  /// retries in case of errors.
  ///
  /// NOTE: the execution of this call can be of any type.
  final DynCall<dynamic, String> callSearch = DynCall<dynamic, String>(
      ['query'], DynCallType.STRING,
      allowRetries: true);

  /// Normal method to do the search. Parameter [query] will be
  /// passed to [callSearch] as input field `query`.
  Future<String?> doSearch(String query) {
    return callSearch.call({'query': query});
  }
}

void main() async {
  var sys = Sys();

  var httpClient = HttpClient('https://www.google.com/');

  var executorFactory = DynCallHttpExecutorFactory(httpClient);

  // Defines the executor of `sys.callSearch` as a HTTP request with a validator
  // that check fo `<html` tag at response.
  //
  // GET: https://www.google.com/search?q=$query
  executorFactory.call(sys.callSearch).executor(HttpMethod.GET,
      path: 'search',
      parametersMap: {'query': 'q'},
      outputValidator: (r, p, rp) => r != null && r.contains('<html'));

  var response = await sys.doSearch('dart dynamic_call');

  print(response);
}
2
likes
120
pub points
50%
popularity

Publisher

unverified uploader

Dynamic Call framework, including API calls integrations (HTTP, RESTful).

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

json_object_mapper, mercury_client, swiss_knife

More

Packages that depend on dynamic_call