No commit activity in last 3 years
No release in over 3 years
It also accepts custom transformations via configuration.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 0.6
~> 10.0
~> 3.1

Runtime

~> 1.3
 Project Readme

roda-parse-request

roda plugin which automatically parses JSON and url-encoded requests

Usage

In your Gemfile:

gem 'roda-parse-request'

In your roda app:

require 'roda'
require 'roda-parse-request'

class App < Roda
  plugin :parse_request

  route do |r|

    r.post do
      # You can use request.parsed_body here
      # By default, it will contain response.body parsed as a json or url-encoded
      # request (if the request was sent with the appropiate content-type headers)
    end
  end
end

Customization

It is possible to add your own parsers to the plugin, like so:

require 'roda'
require 'roda-parse-request'

class App < Roda
  plugin :parse_request, parsers: {
    'upcase'  => ->(data) { data.upcase },
  }

  route do |r|

    r.post do
      # You can still use json and url-encoded parsed requests in request.parsed_body
      # But now, if you get a request with Content-Type = 'upcase', the body
      # will be automatically set to all caps.
    end
  end
end

See the specs for more examples

Running specs

Clone the repo, run bundle and then rspec.

License

MIT License (see LICENSE)