# `Medplum.Client`
[🔗](https://github.com/CodeDuckers-LLC/medplum_elixir/blob/v0.3.0/lib/medplum/client.ex#L1)

Client configuration shared by Medplum API requests.

# `access_token`

```elixir
@type access_token() :: String.t() | nil
```

Bearer token used directly for authenticated requests.

# `auth_mode`

```elixir
@type auth_mode() :: :client_credentials | :access_token
```

Authentication strategy used to authorize requests.

# `base_url`

```elixir
@type base_url() :: String.t()
```

Base Medplum URL without a trailing slash.

# `client_id`

```elixir
@type client_id() :: String.t()
```

OAuth client id used for the client credentials grant.

# `client_secret`

```elixir
@type client_secret() :: String.t()
```

OAuth client secret paired with the client id.

# `fhir_version`

```elixir
@type fhir_version() :: String.t()
```

FHIR version segment used in request paths. Defaults to `"R4"`.

# `headers`

```elixir
@type headers() :: [{String.t(), String.t()}]
```

Default headers merged into every FHIR request.

# `req_options`

```elixir
@type req_options() :: keyword()
```

Extra `Req` options forwarded to outgoing requests.

# `retry`

```elixir
@type retry() :: false | :safe_transient | :transient
```

Retry strategy passed through to `Req`.

# `t`

```elixir
@type t() :: %Medplum.Client{
  access_token: access_token(),
  auth_mode: auth_mode(),
  auth_req_options: req_options(),
  base_url: base_url(),
  cache_tokens: boolean(),
  client_id: client_id(),
  client_secret: client_secret(),
  default_headers: headers(),
  fhir_version: fhir_version(),
  max_retries: non_neg_integer(),
  req_options: req_options(),
  retry: retry(),
  token_refresh_skew: non_neg_integer()
}
```

Client state used to authenticate requests and build FHIR URLs.

# `new`

```elixir
@spec new(keyword() | map()) :: t()
```

Builds a Medplum client.

The `base_url` value is normalized by trimming a trailing slash, and
`fhir_version` defaults to `"R4"` when it is not provided.

By default the client uses the OAuth client credentials grant. When
`access_token` is provided, the client switches to direct bearer-token mode
unless `auth_mode` is set explicitly.

# `new!`

```elixir
@spec new!(keyword() | map()) :: t()
```

Builds a Medplum client and raises on invalid configuration.

# `new_with_access_token`

```elixir
@spec new_with_access_token(keyword() | map(), String.t()) :: t()
```

Builds a Medplum client that uses an existing bearer token directly.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
