onRest method
Implementation
Future<HttpActionResult> onRest(
NodeSpec action, ActionContext context) async {
final spec = action.props;
final uri = UriExtensions.buildUri(spec["url"],
path: spec["path"], queryArgs: spec["queryArgs"]);
final body = spec["body"] != null ? json.safeEncode(spec["body"]!) : null;
final headers = Lowder.actions.getHttpDefaultHeaders(
contentType: spec["body"] != null ? "application/json" : null,
otherHeaders: spec["headers"],
);
var response = await Lowder.actions
.httpCall(uri, spec["method"], body: body, headers: headers);
if (!response.isSuccess) {
if ((await Lowder.actions.onHttpError(response, action, context)).retry) {
response = await Lowder.actions
.httpCall(uri, spec["method"], body: body, headers: headers);
}
}
if (response.isSuccess) {
log.infoWithContext(
"Success calling [${spec["method"]}] $uri", {"body": response.body});
return Lowder.actions.onHttpSuccess(response, action, context);
}
log.info(
"Failure calling [${spec["method"]}] $uri: ${response.statusCode}");
return HttpActionResult(false);
}