FirelyTeam / firely-net-sdk

The official Firely .NET SDK for HL7 FHIR
Other
829 stars 345 forks source link

Relative path for Bundle does not work for pagination #2021

Closed wilsonchenbhs closed 2 years ago

wilsonchenbhs commented 2 years ago

Following the sample found in https://docs.fire.ly/projects/Firely-NET-SDK/client/paging.html , if we return the links (FirstLink/NextLink/PreviousLink/LastLink) as relative path, it would throw the following exception:

while( result != null )
{
    // Do something with the entries in the result Bundle

    // retrieve the next page of results
    result = client.Continue(result);
}

Hl7.Fhir.Rest.FhirOperationException: 'Operation was unsuccessful because of a client error (NotFound). OperationOutcome: Overall result: FAILURE (1 errors and 0 warnings)

[ERROR] (no details)(further diagnostics: Endpoint returned a body with contentType 'application/problem+json', while a valid FHIR xml/json body type was expected. Is this a FHIR endpoint?).'

But, if we return the absolute url, it would be fine. However, it's hard for us to return the absolute url because the app can run:

I know we can add the base path to the app settings and concatenate it before returning the above links, but it's clumsy as we already have the base url passed into FhirClient. Wouldn't it be easier the FhirClient checks if it is not absolute url, then add the base url to it?

mbaltus commented 2 years ago

A Bundle.link.url is of type 'uri', so it has to follow uri syntax and cannot be a relative reference. This means that the application returning the Bundle has to make sure it includes the correct details for a client to use. See also http://hl7.org/fhir/http.html#paging for this.

wilsonchenbhs commented 2 years ago

@mbaltus a .NET Uri can be relative, using UriKind we can specify whether the URI string is a relative URI, absolute URI, or is indeterminate.

image

In terms of the FHIR spec, it does not explicitly make it clear it has to be absolute url:

image
mbaltus commented 2 years ago

Yes, you are correct of course, URIs can be relative. My mistake. However, the FHIR specification mentions this in relation to paging and the links in the Bundle:

The links are opaque to the client, have no dictated structure, and only the server understands them. The client must use the server supplied links in order to traverse the pages.

So in this case, I would not expect the FhirClient to have to do any work to use a paging link.

wilsonchenbhs commented 2 years ago

Ok, in that case, I guess we will have to build the absolute url. Thanks!