Sha256: 0f96ac677ed8727f3d1b7d4a664f8b4777faa4e80229c928c701b21023b11f2f

Contents?: true

Size: 1.01 KB

Versions: 55

Compression:

Stored size: 1.01 KB

Contents

# *Flexirest:* Default parameters

If you want to specify default parameters you shouldn't use a path like:

```ruby
class Person < Flexirest::Base
  get :all, '/people?all=true' # THIS IS WRONG!!!
end
```

You should use a defaults option to specify the defaults, then they will be correctly overwritten when making the request

```ruby
class Person < Flexirest::Base
  get :all, '/people', :defaults => {:active => true}
end

@people = Person.all(active:false)
```

If you specify `defaults` as a `Proc` this will be executed with the set parameters (which you can change). For example to allow you to specify a reference (but the API wants it formated as "id-reference") you could use:

```ruby
class Person < Flexirest::Base
  get :all, "/", defaults: (Proc.new do |params|
    reference = params.delete(:reference) # Delete the old parameter
    {
      id: "id-#{reference}"
    } # The last thing is the hash of defaults
  end)
end
```


-----

[< Translating APIs](translating-apis.md) | [Root elements >](root-elements.md)

Version data entries

55 entries across 55 versions & 1 rubygems

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