Sha256: 2cb9f0a99b7e76359a56cf1dcc51f0866f0b856ca8acb7f238fd2ec8e2b767e4

Contents?: true

Size: 1.8 KB

Versions: 7

Compression:

Stored size: 1.8 KB

Contents

Configuration
===

## Configure LHC on initialisation

If you want to configure LHC on initialisation (like in a Rails initializer, environment.rb or application.rb), you could run into the problem that certain configurations can only be set once.
You can use `LHC.configure` to prevent the initialisation problem.
Take care that you only use `LHC.configure` once, because it is actually reseting previously made configurations and applies the new once.

```ruby

  LHC.configure do |c|
    c.placeholder :datastore, 'http://datastore.lb-service/v2'
    c.endpoint :feedbacks, ':datastore/feedbacks'
    c.interceptors = [CachingInterceptor, MonitorInterceptor, TrackingIdInterceptor]
  end

```

## Endpoints

You can configure endpoints, for later use, by giving them a name, an url and some parameters (optional).

```ruby
  url = 'http://datastore.lb-service/v2/feedbacks'
  options = { params: { has_reviews: true } }
  LHC.config.endpoint(:feedbacks, url, options)
  LHC.get(:feedbacks)
```

Explicit request options override configured options.

```ruby
  LHC.get(:feedbacks, params: { has_reviews: false }) # Overrides configured params
```

## Placeholders

You can configure global placeholders, that are used when generating urls from url-templates.

```ruby
  LHC.config.placeholder(:datastore, 'http://datastore.lb-service/v2')
  options = { params: { has_reviews: true } }
  LHC.config.endpoint(:feedbacks, url, options)
  LHC.get(:feedbacks)
```

## Interceptors

To enable interceptors you have to configure LHC's interceptors for http communication.
The global default interceptors are processed in the order you provide them.

```ruby
  LHC.config.interceptors = [CachingInterceptor, MonitorInterceptor, TrackingIdInterceptor]
```

You can only set the list of global interceptors once and you can not alter it after you set it.

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lhc-3.1.1 docs/configuration.md
lhc-3.1.0 docs/configuration.md
lhc-3.0.0 docs/configuration.md
lhc-2.0.0 docs/configuration.md
lhc-1.2.0 docs/configuration.md
lhc-1.1.0 docs/configuration.md
lhc-0.2.1 docs/configuration.md