---
title: Backend
summary: A named backend.
url: https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/
---

**Kind:** Struct  
**Module:** [backend](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/)  
**Package:** fastly 0.13.1  
**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#101

```rust
pub struct Backend { /* private fields */ }
```

A named backend.

This represents a backend associated with a service that we can send requests to, potentially
caching the responses received.

Backends come in one of two flavors:
  * **Static Backends**: These backends are created using the Fastly UI or API,
    and are predefined by the user. Static backends have short names (see the
    precise naming rules in [`Backend::from_name`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-from_name)) that are usable across every
    session of a service.
  * **Dynamic Backends**: These backends are created programmatically using the
    [`Backend::builder`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-builder) API. They are defined at runtime, and may or may not be
    shared across sessions depending on how they are configured.

To use a backend, pass it to the [`crate::Request::send`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/request/struct.Request/#method-send) method. Alternatively, the following
values can be automatically coerced into a backend for you, without the need to explicitly
create a `Backend` object, although they may all induce panics:

  * Any string type ([`&str`](https://doc.rust-lang.org/stable/std/primitive.str.html), [`String`, or `&String`](https://doc.rust-lang.org/stable/alloc/string/struct.String.html)) will
    be automatically turned into the static backend of the same name.

### Using Static Backends

As stated at the top level, the following snippet is a minimal program that resends
a request to a static backend named "example_backend":

```rust
use fastly::{Error, Request, Response};

#[fastly::main]
fn main(ds_req: Request) -> Result<Response, Error> {
    Ok(ds_req.send("example_backend")?)
}
```

A safer alternative to this example would be the following:

```rust
use fastly::{Backend, Error, Request, Response};

#[fastly::main]
fn main(ds_req: Request) -> Result<Response, Error> {
    match Backend::from_name("example_backend") {
       Ok(backend) => Ok(ds_req.send(backend)?),
       Err(_) => {
            // custom backend failure response
            unimplemented!()
       }
    }
}
```

as this version allows you to handle backend errors more cleanly.

### Validating Support for Dynamic Backends

Since dynamic backends are only enabled for some services, it may be particularly
useful to ensure that dynamic backends are supported in your Compute service.
The easiest way to do so is to try to create a dynamic backend, and then explicitly
check for the [`crate::backend::BackendCreationError::Disallowed`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/enum.BackendCreationError/) code, as follows:

```rust
use fastly::{Backend, Error, Request, Response};
use fastly::backend::BackendCreationError;

#[fastly::main]
fn main(ds_req: Request) -> Result<Response, Error> {
    match Backend::builder("custom_backend", "example.org:993").finish() {
        Ok(backend) => Ok(ds_req.send(backend)?),
        Err(BackendCreationError::Disallowed) => {
           // custom code ofr handling when dynamic backends aren't supported
           unimplemented!()
        }
        Err(err) => {
           // more specific logging/handling for backend misconfigurations
           unimplemented!()
        }
    }
}
```

## Methods

### builder

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#126

```rust
fn builder(name: impl ToString, target: impl ToString) -> BackendBuilder
```

Create a new dynamic backend builder.

The arguments are the name of the new backend to use, along with a string
describing the backend host. The latter can be of the form:

   * `"<ip address>"`
   * `"<hostname>"`
   * `"<ip address>:<port>"`
   * `"<hostname>:<port>"`

The name can be whatever you would like, as long as it does not match the name
of any of the static service backends nor match any other dynamic backends built
during this session. (Names can overlap between different sessions of the same
service -- they will be treated as completely separate entities and will not be
pooled -- but you cannot, for example, declare a dynamic backend named
"dynamic-backend" twice in the same session.)

The builder will start with default values for all other possible fields for the
backend, which can be overridden using the other methods provided. Call
`finish()` to complete the construction of the dynamic backend.

Dynamic backends must be enabled for this Compute service. You can determine
whether or not dynamic backends have been allowed for the current service by
using this builder, and then checking for the `BackendCreationError::Disallowed`
error result. This error only arises when attempting to use dynamic backends
with a service that has not had dynamic backends enabled, or dynamic backends
have been administratively prohibited for the node in response to an ongoing
incident.

**Parameters**

- `name`: `impl ToString`
- `target`: `impl ToString`

**Returns**

`BackendBuilder`

### exists

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#156

```rust
fn exists(&self) -> bool
```

Returns true if a backend with this name exists.

**Parameters**

- `self`: `&Self`

**Returns**

`bool`

### from_name

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#121

```rust
fn from_name(s: &str) -> Result<Self, BackendError>
```

Get a backend by its name.

This function will return a [`BackendError`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/enum.BackendError/) if an invalid name was given.

Backend names:
  * cannot be empty
  * cannot be longer than 255 characters
  * cannot ASCII control characters such as `'\n'` or `DELETE`.
  * cannot contain special Unicode characters
  * should only contain visible ASCII characters or spaces

Future versions of this function may return an error if your service does not have a backend
with this name.

**Parameters**

- `s`: `&str`

**Returns**

`Result<Self, BackendError>`

### get_between_bytes_timeout

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#441

```rust
fn get_between_bytes_timeout(&self) -> Duration
```

Returns the "between bytes" timeout for this backend.

This timeout applies between any two bytes we receive across the wire.

Use
[`BackendBuilder::between_bytes_timeout`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.BackendBuilder/#method-between_bytes_timeout)
to set this for a dynamic backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`Duration`

### get_connect_timeout

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#369

```rust
fn get_connect_timeout(&self) -> Duration
```

Returns the connection timeout for this backend.

Use
[`BackendBuilder::connect_timeout`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.BackendBuilder/#method-connect_timeout)
to set this for a dynamic backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`Duration`

### get_first_byte_timeout

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#405

```rust
fn get_first_byte_timeout(&self) -> Duration
```

Returns the "first byte" timeout for this backend.

This timeout applies between the time of connection and the time we get the first byte back.

Use
[`BackendBuilder::first_byte_timeout`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.BackendBuilder/#method-first_byte_timeout)
to set this for a dynamic backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`Duration`

### get_host

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#201

```rust
fn get_host(&self) -> String
```

Returns the hostname for this backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`String`

### get_host_override

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#274

```rust
fn get_host_override(&self) -> Option<HeaderValue>
```

Returns the host header override when contacting this backend.

This method returns `None` if no host header override is configured for this backend.

This is used to change the `Host` header sent to the backend. For more information, see
the Fastly documentation on host overrides here:
<https://docs.fastly.com/en/guides/specifying-an-override-host>

Use
[`BackendBuilder::override_host`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.BackendBuilder/#method-override_host)
to set this for a dynamic backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`Option<HeaderValue>`

### get_http_keepalive_time

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#476

```rust
fn get_http_keepalive_time(&self) -> Duration
```

Returns the time to hold onto an idle HTTP keepalive connection after it was last used
before closing it.

Use
[`BackendBuilder::http_keepalive_time`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.BackendBuilder/#method-http_keepalive_time)
to set this for a dynamic backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`Duration`

### get_port

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#342

```rust
fn get_port(&self) -> u16
```

Get the port number of the backend's address.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`u16`

### get_ssl_max_version

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#721

```rust
fn get_ssl_max_version(&self) -> Option<SslVersion>
```

Returns the maximum TLS version for connecting to the backend.

This method returns `None` if SSL/TLS is not enabled for this backend.

Use
[`BackendBuilder::set_max_tls_version`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.BackendBuilder/#method-set_max_tls_version)
to set this for a dynamic backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`Option<SslVersion>`

### get_ssl_min_version

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#674

```rust
fn get_ssl_min_version(&self) -> Option<SslVersion>
```

Returns the minimum TLS version for connecting to the backend.

This method returns `None` if SSL/TLS is not enabled for this backend.

Use
[`BackendBuilder::set_min_tls_version`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.BackendBuilder/#method-set_min_tls_version)
to set this for a dynamic backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`Option<SslVersion>`

### get_tcp_keepalive_enable

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#510

```rust
fn get_tcp_keepalive_enable(&self) -> bool
```

Returns `true` if TCP keepalives have been enabled for this backend.

Use
[`BackendBuilder::tcp_keepalive_enable`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.BackendBuilder/#method-tcp_keepalive_enable)
to set this for a dynamic backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`bool`

### get_tcp_keepalive_interval

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#542

```rust
fn get_tcp_keepalive_interval(&self) -> Duration
```

Returns the time to wait in between sending each TCP keepalive probe to this backend.

Use
[`BackendBuilder::tcp_keepalive_interval_secs`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.BackendBuilder/#method-tcp_keepalive_interval_secs)
to set this for a dynamic backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`Duration`

### get_tcp_keepalive_probes

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#577

```rust
fn get_tcp_keepalive_probes(&self) -> u32
```

Returns the time to wait after the last data was sent before starting to send TCP keepalive
probes to this backend.

Use
[`BackendBuilder::tcp_keepalive_probes`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.BackendBuilder/#method-tcp_keepalive_probes)
to set this for a dynamic backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`u32`

### get_tcp_keepalive_time

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#610

```rust
fn get_tcp_keepalive_time(&self) -> Duration
```

Returns the time to wait after the last data was sent before starting to send TCP keepalive
probes to this backend.

Use
[`BackendBuilder::tcp_keepalive_time_secs`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.BackendBuilder/#method-tcp_keepalive_time_secs)
to set this for a dynamic backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`Duration`

### healthcheck_builder

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/experimental/dynamic_backend_healthchecks.rs#260

```rust
fn healthcheck_builder(host: impl ToString) -> HealthcheckBuilder
```

Create a new health check builder for a dynamic backend.

The argument is a string describing the backend host on which to check health
checks on. This can be of the form:

   * `"<ip address>"`
   * `"<hostname>"`
   * `"<ip address>:<port>"`
   * `"<hostname>:<port>"`

The builder will start with default values for all other possible fields for the
health check, which can be overridden using the other methods provided. Use 
`BackendBuilder::healthcheck` to add the health check to a specific Dynamic Backend
and call `BackendBuilder::finish()` to complete the construction of the dynamic backend.

Values for health checks have strict limits to prevent ill-use. If you create a health
check with a value that breaks these limits, `finish()` will error with a 
`BackendCreationError:InvalidHealthcheckValues`

**Parameters**

- `host`: `impl ToString`

**Returns**

`HealthcheckBuilder`

### into_string

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#136

```rust
fn into_string(self) -> String
```

Turn the backend into its name as a string.

**Parameters**

- `self`: `Self`

**Returns**

`String`

### is_dynamic

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#178

```rust
fn is_dynamic(&self) -> bool
```

Returns true if this is a dynamic backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`bool`

### is_ssl

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#645

```rust
fn is_ssl(&self) -> bool
```

Returns `true` if SSL/TLS is used to connect to the backend.

Use
[`BackendBuilder::enable_ssl`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.BackendBuilder/#method-enable_ssl) or
[`BackendBuilder::disable_ssl`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.BackendBuilder/#method-disable_ssl)
to set this for a dynamic backend.

#### Panics

If the [`name()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-name) of this backend does not match any of the backends associated
with this service, this function will panic. Use [`exists()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/backend/struct.Backend/#method-exists) to explicitly
check that this backend exists.

**Parameters**

- `self`: `&Self`

**Returns**

`bool`

### name

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#131

```rust
fn name(&self) -> &str
```

Get the name of this backend.

**Parameters**

- `self`: `&Self`

**Returns**

`&str`

## Trait implementations

### impl BackendExt for Backend

#### is_healthy

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/experimental.rs#377

```rust
fn is_healthy(&self) -> Result<BackendHealth, Error>
```

**Parameters**

- `self`: `&Self`

**Returns**

`Result<BackendHealth, Error>`

### impl Clone for Backend

#### clone

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#100

```rust
fn clone(&self) -> Self
```

**Parameters**

- `self`: `&Self`

**Returns**

`Self`

### impl Debug for Backend

#### fmt

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#99

```rust
fn fmt(&self, f: &mut Formatter<'_>) -> Result
```

**Parameters**

- `self`: `&Self`
- `f`: `&mut $crate::fmt::Formatter`

**Returns**

`$crate::fmt::Result`

### impl Display for Backend

#### fmt

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#807

```rust
fn fmt(&self, f: &mut Formatter<'_>) -> Result
```

**Parameters**

- `self`: `&Self`
- `f`: `&mut std::fmt::Formatter`

**Returns**

`std::fmt::Result`

### impl FromStr for Backend

#### from_str

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#784

```rust
fn from_str(s: &str) -> Result<Self, Self::Err>
```

**Parameters**

- `s`: `&str`

**Returns**

`Result<Self, Self::Err>`

### impl Hash for Backend

#### hash

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#100

```rust
fn hash<__H: Hasher>(&self, state: &mut __H)
```

**Parameters**

- `self`: `&Self`
- `state`: `&mut __H`

### impl Ord for Backend

#### cmp

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#100

```rust
fn cmp(&self, other: &Self) -> Ordering
```

**Parameters**

- `self`: `&Self`
- `other`: `&Self`

**Returns**

`$crate::cmp::Ordering`

### impl PartialEq for Backend

#### eq

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#100

```rust
fn eq(&self, other: &Self) -> bool
```

**Parameters**

- `self`: `&Self`
- `other`: `&Self`

**Returns**

`bool`

### impl PartialOrd for Backend

#### partial_cmp

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/backend.rs#100

```rust
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
```

**Parameters**

- `self`: `&Self`
- `other`: `&Self`

**Returns**

`$crate::option::Option<$crate::cmp::Ordering>`

## Auto trait implementations

- `Freeze`
- `RefUnwindSafe`
- `Send`
- `Sync`
- `Unpin`
- `UnsafeUnpin`
- `UnwindSafe`

## Blanket implementations

- `Any`
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Comparable<K>`
- `Downcast`
- `DowncastSync`
- `Equivalent<K>`
- `ErasedDestructor`
- `From<T>`
- `Into<U>`
- `IntoEither`
- `Same`
- `ToOwned`
- `ToString`
- `TryFrom<U>`
- `TryInto<U>`
