fhir_put {fhircrackr} | R Documentation |
PUT to a FHIR server
Description
This function is a convenience wrapper around httr::PUT()
.
Usage
fhir_put(
url,
body,
username = NULL,
password = NULL,
token = NULL,
add_headers = NULL,
verbose = 1,
log_errors = NULL
)
Arguments
url |
An object of class fhir_url or a character vector of length one containing the url to PUT to. |
body |
An object of class fhir_resource or fhir_body. See details for how to generate them. |
username |
A character vector of length one containing the username for basic authentication. |
password |
A character vector of length one containing the password for basic authentication. |
token |
A character vector of length one or object of class httr::Token, for bearer token authentication (e.g. OAuth2). See |
add_headers |
A named character vector of custom headers to add to the HTTP request, e.g. |
verbose |
An integer vector of length one. If 0, nothing is printed, if > 0 success message is printed. Defaults to 1. |
log_errors |
Either |
Details
fhir_put()
accepts two classes for the body:
A fhir_resource as created by
fhir_build_resource()
. This is used when just a single resource should be PUT to the server. In this caseurl
must contain the base url plus the resource type and the resource id, e.g. http://hapi.fhir.org/baseR4/Patient/1a2b3c.A fhir_body as created by
fhir_body()
. This is the most flexible approach, because within the fhir_body object you can represent any kind ofcontent
as a string and set thetype
accordingly. See examples.
For examples of how to create the different body types see the respective help pages. For an example of the entire workflow around creating and PUTing resources, see the package vignette on recreating resources.
Examples
## Not run:
### 1. PUT fhir__resource object
#unserialize example resource
resource <- fhir_unserialize(example_resource2)
#have a look at the resource
resource
#put
fhir_put(url = "http://hapi.fhir.org/baseR4/Patient/1a2b3c", body = resource)
### 2. PUT fhir_body object
#define body
body <- fhir_body(content = "<Patient> <id value='x1y2'/> <gender value='female'/> </Patient>",
type = "xml")
#put
fhir_put(url = "http://hapi.fhir.org/baseR4/Patient/x1y2", body = body)
## End(Not run)