FHIRMinimalServer

open class FHIRMinimalServer: FHIRServer

A minimal FHIRServer implementation that deals with Open FHIR servers in JSON.

These methods are of interest to you when you create a subclass:

  • handlerForRequest(withMethod:resource:): what kind of handler your server wants to use. Returns FHIRJSONRequestHandler.
  • configurableRequest(for:): the SMART framework returns a request that already has an Authorization headers set, if needed.
  • The server’s base URL.

    Declaration

    Swift

    public final let baseURL: URL
  • Main initializer. Makes sure the base URL ends with a / to facilitate URL generation later on.

    Declaration

    Swift

    public required init(baseURL base: URL, auth: [String: Any]? = nil)
  • This method simply creates an absolute URL from the receiver’s baseURL and the given path.

    A chance for subclasses to mess with URL generation if needed.

    Declaration

    Swift

    open func absoluteURL(for path: String, handler: FHIRRequestHandler) -> URL?

    Parameters

    for

    The path in the absolute URL

  • The server can return the appropriate request handler for the type and resource combination.

    Request handlers are responsible for constructing an URLRequest that correctly performs the desired REST interaction.

    Declaration

    Swift

    open func handlerForRequest(withMethod method: FHIRRequestMethod, resource: Resource?) -> FHIRRequestHandler?

    Parameters

    method

    The request method (GET, PUT, POST or DELETE)

    resource

    The resource to be involved in the request, if any

    Return Value

    An appropriate FHIRRequestHandler, for example a if sending and receiving JSON

  • Pre-prepare a mutable URLRequest that the handler subsequently prepares and performs.

    This implementation simply creates an URLRequest against the given url.

    Declaration

    Swift

    open func configurableRequest(for url: URL) -> URLRequest

    Parameters

    url

    The url to use for the request

    Return Value

    A URLRequest instance

  • Method to execute a request against a given relative URL with a given request/response handler.

    Declaration

    Swift

    open func performRequest(against path: String, handler: FHIRRequestHandler, callback: @escaping ((FHIRServerResponse) -> Void))

    Parameters

    path

    The path, relative to the server’s base; may include URL query and URL fragment (!)

    handler

    The FHIRRequestHandler that prepares the request and processes the response

    callback

    The callback to execute; NOT guaranteed to be performed on the main thread!

  • Method to execute a request against a given absolute URL with a given request/response handler.

    This method will use the request handler to prepare the request (i.e. add headers and prepare body data), then hand it over to perform(request:completionHandler:) to actually perform the request. Finally, the response data/URLResponse/error is handed to the request handler and converted into the FHIRServerResponse that is delivered to you in the callback.

    Declaration

    Swift

    open func performRequest(on url: URL, handler: FHIRRequestHandler, callback: @escaping ((FHIRServerResponse) -> Void))

    Parameters

    url

    The full URL; may include query parts and fragment (!)

    handler

    The FHIRRequestHandler that prepares the request and processes the response

    callback

    The callback to execute; NOT guaranteed to be performed on the main thread!

  • This is the last method in the chain to actually perform a request. Uses URLSession().dataTask(with:completionHandler:).

    Declaration

    Swift

    open func perform(request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionTask?

    Parameters

    request

    The URL request to perform as-is

    completionHandler

    The completion handler, returning optional data, response and error instances, when all has completed

    Return Value

    A URLSessionTask that is already under way

  • Undocumented

    Declaration

    Swift

    open class FHIRMinimalServer: FHIRServer
  • Create the server’s default session. Override in subclasses to customize URLSession behavior.

    Declaration

    Swift

    open func createDefaultSession() -> URLSession