get method

  1. @override
Resource? get(
  1. Link link
)
override

A service can return a Resource to:

  • respond to a request to its web API declared in links,
  • serve additional resources on behalf of the publication,
  • replace a publication resource by its own version.

Called by Publication.get for each request.

Warning: If you need to request one of the publication resources to answer the request, use the Fetcher provided by the PublicationServiceContext instead of Publication.get, otherwise it will trigger an infinite loop.

@return The Resource containing the response, or null if the service doesn't recognize this request.

Implementation

@override
Resource? get(Link link) {
  if (link.href != _positionsLink.href) {
    return null;
  }
  return StringResource(_positionsLink, () async {
    List<JSONable> positionList = await positions();
    return json.encode({
      "total": positionList.length,
      "positions": positionList.toJson(),
    });
  });
}