CloudflareStorage is a simple gem for interacting with the Cloudflare Workers KV Storage from a Rails application.
It was designed to let you get started with minimal configuration.
Read a more detailed writeup here.
Add this line to your application's Gemfile:
gem 'cloudflare_storage'
And then run:
bundle
Or install it yourself:
gem install cloudflare_storage
Configure credentials with an initializer. For example:
# config/initializers/cloudflare_storage.rb
CloudflareStorage.configure do |config|
config.account_id = Rails.application.credentials.cloudflare.account_id
config.namespace_id = Rails.application.credentials.cloudflare.namespace_id
config.token = Rails.application.credentials.cloudflare.token
end
end
Now you can simply call CloudflareStorage
in your code to read, write, and list from Workers KV storage. I.e.
CloudflareStorage.write('foo', 'bar')
CloudflareStorage.read('foo') # Returns 'bar'
CloudflareStorage.list('fo') # Lists all keys starting with 'fo'
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, then create a new git tag and push it. Github actions will take care of the rest.
Bug reports and pull requests are welcome on GitHub at https://github.com/geetotes/cloudflare_storage.
The gem is available as open source under the terms of the MIT License.
There are other gems out there that encompass the whole of the Cloudflare API. You should look to those if you're planning on using more than just Workers KV storage in your project.