Sha256: 2b4284f74f802ff66279fabe9889b21ecb8065117a64a0ce5db0aa5375b00100

Contents?: true

Size: 1.43 KB

Versions: 19

Compression:

Stored size: 1.43 KB

Contents

# *Flexirest:* Root elements

If your response comes back with a root node and you'd like to ignore it, you can define the mapping as:

```ruby
Flexirest::Base.ignore_root = "data"
```

Any `ignore_root` setting in specific class overrides this declared default.

```ruby
class Feed < Flexirest::Base
  ignore_root: "feed"

  post :list, "/feed"
end
```

And any `ignore_root` setting in specific request overrides the both default and class specific setting.


```ruby
class Feed < Flexirest::Base
  ignore_root: 'feed'

  post :list, "/feed", ignore_root: "result"
end
```

You can also assign an array to `ignore_root` if you'd want to remove a tree of root nodes.

```ruby
class Feed < Flexirest::Base
  post :list, "/feed", ignore_root: ["feed", "items"]
end
```

Alternatively if you want to wrap your JSON request body in a root element, e.g.:

```json
{
  "feed": {
    "id": 1
  }
}
```

You can do it using `wrap_root`:

```ruby
Flexirest::Base.wrap_root = "data"
```

Any `wrap_root` setting in specific class overrides this declared default.

```ruby
class Feed < Flexirest::Base
  wrap_root: "feed"

  post :list, "/feed"
end
```

And any `wrap_root` setting in specific request overrides the both default and class specific setting.


```ruby
class Feed < Flexirest::Base
  wrap_root: 'feed'

  post :list, "/feed", wrap_root: "data"
end
```

-----

[< Default parameters](default-parameters.md) | [Required parameters >](required-parameters.md)

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
flexirest-1.12.4 docs/root-elements.md
flexirest-1.12.3 docs/root-elements.md
flexirest-1.12.2 docs/root-elements.md
flexirest-1.12.1 docs/root-elements.md
flexirest-1.12.0 docs/root-elements.md
flexirest-1.11.3 docs/root-elements.md
flexirest-1.11.2 docs/root-elements.md
flexirest-1.11.1 docs/root-elements.md
flexirest-1.11.0 docs/root-elements.md
flexirest-1.10.12 docs/root-elements.md
flexirest-1.10.11 docs/root-elements.md
flexirest-1.10.10 docs/root-elements.md
flexirest-1.10.9 docs/root-elements.md
flexirest-1.10.8 docs/root-elements.md
flexirest-1.10.7 docs/root-elements.md
flexirest-1.10.6 docs/root-elements.md
flexirest-1.10.5 docs/root-elements.md
flexirest-1.10.4 docs/root-elements.md
flexirest-1.10.3 docs/root-elements.md