FHIRServerResponse
public protocol FHIRServerResponse
Encapsulates a server response, which can also indicate that there was no response or not even a request, in which case the error
property carries the only useful information.
-
The HTTP status code.
Declaration
Swift
var status: Int
-
Response headers.
Declaration
Swift
var headers: [String: String]
-
The response body data.
Declaration
Swift
var body: Data?
-
The request’s operation outcome, if any.
Declaration
Swift
var outcome: OperationOutcome?
-
The error encountered, if any.
Declaration
Swift
var error: FHIRError?
-
Extract the resource of the given type from the response, if possible.
Throws
Errors if there was no response, if it was of a different type or if there were errors in the dataDeclaration
Swift
func responseResource<T: Resource>(ofType: T.Type) throws -> T
Parameters
ofType
The type of resource to extract
Return Value
The resource that was found in the response if it is of the desired type
-
applyHeaders(to:)
Default implementationThe response should inspect response headers and update resource data like
id
andmeta
accordingly.This method must not be called if the response has a non-nil error.
Throws
The method should only throw on severe cases, like if Location headers were returned that don’t match the resource typeDefault Implementation
The base implementation inspects response headers (
Location
,Last-Modified
andETag
) and updates the resource’sid
andmeta
accordingly.This method must not be called if the response has a non-nil error.
Declaration
Swift
func applyHeaders(to: Resource) throws
Parameters
to
The resource to apply response data to
-
The response should apply response body data to the given resource. It should throw
FHIRError.responseNoResourceReceived
if there was no response data.This method must not be called if the response has a non-nil error.
Throws
The method should throw if resource data was returned that doesn’t match the given resource’s type, but also if there was no response data at all (FHIRError.ResponseNoResourceReceived
in that case)Declaration
Swift
func applyBody(to: Resource) throws
Parameters
to
The resource to apply response data to
-
debugDescription
Extension methodNicely format status code, response headers and response body (if any).
Declaration
Swift
public var debugDescription: String