api_client 2.2.0
api_client: ^2.2.0

Dart native js
Flutter Android iOS web

A simple schema api client. Helps to deal with API calls via an API specification

api_client #

Build Status

A schema api's client

Set up Spec #

final Spec spec = Spec(
      endpoints: {
        "get_pet": get("{{api_url}}/{{version}}/pet/{{pet_id}}"),
      },
      parameters: {
        "api_url": "https://petstore.swagger.io",
        "version": "v2",
      },
      onSend: (Request request) {
        JsonRequestMiddleware(request);
        request.set("start_time", DateTime.now().millisecondsSinceEpoch);
      },
      onReceive: (Request request, Response response) {
        int startTime = request.get("start_time");
        int endTime = DateTime.now().millisecondsSinceEpoch;
        print(
            "Request ${response.httpResponse.request.url.toString()} is completed in ${endTime - startTime} (ms)");
      });

Call API #

spec.call("get_pet", parameters: {"pet_id": 123})
    .then((response) {
  if (response.statusCode == 200) {
     print(json.decode(utf8.decode(response.bodyBytes)));
  }
});

Function Arguments of call

  • name: (requires) name of spec
  • parameters: (optional) contextual parameters for current call
  • onSend, onReceive, onError: (optional) see Events

Events #

Applicable for initializing Spec and on each call

  • onSend(Request request) executes before request is sent
  • onReceive(Request request, Response response) executes after receiving response
  • onError(Request request, Response response, Exception exception) executes when there is an error
0
likes
90
pub points
29%
popularity

A simple schema api client. Helps to deal with API calls via an API specification

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

me@dotronglong.com

License

BSD (LICENSE)

Dependencies

emitter, http

More

Packages that depend on api_client