Sha256: 7d41316ad9d6651dd9ff73ffd3f1d191ef1fca5c2b648716fb0304fc81c681bc

Contents?: true

Size: 1.04 KB

Versions: 24

Compression:

Stored size: 1.04 KB

Contents

# *Flexirest:* Faking calls

There are times when an API hasn't been developed yet, so you want to fake the API call response. To do this, you can simply pass a `:fake` option when mapping the call containing the response.

```ruby
class Person < Flexirest::Base
  get :all, '/people', fake: [{first_name:"Johnny"}, {first_name:"Bob"}]
end
```

You may want to run a proc when faking data (to put information from the parameters in to the response or return different responses depending on the parameters). To do this just pass a proc to `:fake`:

```ruby
class Person < Flexirest::Base
  get :all, '/people', fake: ->(request) { {result: request.get_params[:id]} }
end
```

Alternatively, you can specify a symbol as the `fake` parameter, and Flexirest will call that method to get a string JSON as if it was the request body:

```ruby
class Person < Flexirest::Base
  get :all, '/people', fake: :get_data

  def get_data
    {result: true}.to_json
  end
end
```

-----

[< Parallel requests](parallel-requests.md) | [Per-request timeouts >](per-request-timeouts.md)

Version data entries

24 entries across 24 versions & 1 rubygems

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