A schema api's client
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)");
});
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 specparameters
: (optional) contextual parameters for current callonSend
,onReceive
,onError
: (optional) seeEvents
Applicable for initializing Spec
and on each call
onSend(Request request)
executes before request is sentonReceive(Request request, Response response)
executes after receiving responseonError(Request request, Response response, Exception exception)
executes when there is an error