fhir_post | R Documentation |
This function is a convenience wrapper around httr::POST()
.
fhir_post(
url,
body,
username = NULL,
password = NULL,
token = NULL,
add_headers = NULL,
verbose = 1,
log_errors = NULL
)
## S4 method for signature 'ANY,fhir_resource'
fhir_post(
url,
body,
username = NULL,
password = NULL,
token = NULL,
add_headers = NULL,
verbose = 1,
log_errors = NULL
)
## S4 method for signature 'ANY,fhir_bundle_xml'
fhir_post(
url,
body,
username = NULL,
password = NULL,
token = NULL,
add_headers = NULL,
verbose = 1,
log_errors = NULL
)
## S4 method for signature 'ANY,fhir_body'
fhir_post(
url,
body,
username = NULL,
password = NULL,
token = NULL,
add_headers = NULL,
verbose = 1,
log_errors = NULL
)
url |
An object of class fhir_url or a character vector of length one containing the url to POST to. |
body |
An object of class fhir_resource, fhir_bundle_xml 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 |
fhir_post()
accepts four classes for the body:
A fhir_resource as created by fhir_build_resource()
. This is used when just a single resource should be POSTed to the server.
In this case url
must contain the base url plus the resource type, e.g. http://hapi.fhir.org/baseR4/Patient.
A fhir_bundle_xml representing a transaction or batch bundle as created by fhir_build_bundle()
.
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 of content
as a string and set the type
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 POSTing resources, see the package vignette on recreating resources.
## Not run:
### 1. POST transaction bundle
#unserialize example bundles
bundle <- fhir_unserialize(transaction_bundle_example)
#have a look at the bundle
cat(toString(bundle))
#post
fhir_post(url = "http://hapi.fhir.org/baseR4", body = bundle)
### 2. POST single resouce
#unserialize example resource
resource <- fhir_unserialize(example_resource1)
#have a look at the resource
resource
#post
url <- fhir_url(url = "http://hapi.fhir.org/baseR4", resource = "Patient")
fhir_post(url = url, body = resource)
### 3. POST arbitrary body
#define body
body <- fhir_body(content = "<Patient> <gender value='female'/> </Patient>", type = "xml")
#post
url <- fhir_url(url = "http://hapi.fhir.org/baseR4", resource = "Patient")
fhir_post(url = url, body = body)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.