tool to mock API endpoints
Development tool to mock API endpoints quickly and easily (docker image available)
Nothing special found.
DuckRails is a development tool.
Its main purpose is to allow developers to quickly mock API endpoints that for many possible reasons they can't reach at a specific time.
If it looks like a duck, walks like a duck and quacks like a duck, then it's a duck :duck:
The application allows creating new routes dynamically to which developers can assign static or dynamic responses:
or even cause delays, timeouts etc.
The repository's wiki pages contain all you need to know.
* What is DuckRails?
* Setting up the application
* natively
* via docker
* Using DuckRails
* The mock form
* The mock index page
* Creating mocks
* Route paths with variables
* Static mock
* Dynamic mock with embedded Ruby
* Dynamic mock with JavaScript
* Mock wrapping an existing API call
* Advanced mock (WIP)
You can find the old DuckRails' guides at my blog.
Mocks index page
Changing mocks order
Setting general mock properties
Defining the response body
Setting response headers
Setting some advanced configuration (delays, dynamic headers, content type & status)
Upon save the route becomes available to the application and you can use the endpoint:
You can define static or dynamic responses for a mock.
Currently supported dynamic types are:
When specifying dynamic content of embedded Ruby (more options to be added), you can read as local variables:
@parameters
: The parameters of the request@request
: The request@response
: The responseWhen specifying dynamic content of JavaScript type, you can read as local variables:
parameters
: The parameters of the requestheaders
: The request headersThe script should always return a string (for JSON use JSON.stringify(your_variable)
)
You can specify routes and access their parts in the @parameters variable, for example:
/authors/:author_id/posts/:post_id
give you access to the parameters with:
@parameters[:author_id]
@parameters[:post_id]
config/database.yml.sample
) under config/database.yml
and edit it to reflect your preferred db configuration (defaults to sqlite3). If you change the database adapter, make sure you include the appropriate gem in your Gemfile
(ex. for mysql gem 'mysql2'
)bundle install
to install the required gems.rake db:setup
to setup the database.rails server
to start the application on the default port.bundle exec puma -t 8:16 -w 3
config/database.yml.sample
) under config/database.yml
and edit it to reflect your preferred db configuration (defaults to sqlite3). If you change the database adapter, make sure you include the appropriate gem in your Gemfile
(ex. for mysql gem 'mysql2'
)bundle install
to install the required gems.export SECRET_KEY_BASE="your_secret_key_base_here"
RAILS_ENV=production rake db:setup
to setup the database.RAILS_ENV=production rake assets:precompile
to generate the assets.bundle exec rails s -e production
to start the application on the default port.RAILS_ENV=production bundle exec puma -t 8:16 -w 3
The application is by default configured to use sqlite3. If you want to use another configuration, update the config/database.yml
accordingly to match your setup.
A docker image is available at docker hub under iridakos/duckrails.
To obtain the image use:
docker pull iridakos/duckrails
To start the application and bind it to a port (ex. 4000) use:
docker run -p 4000:80 iridakos/duckrails:latest
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)This application is open source under the MIT License terms.