Sometimes you want to support both GET and POST in a Grape API.
If you want to support GET you would write something like get [path] do
. If you want to support POST you would write post [path] do
. What are those get and post methods anyway? The answer is in Grape’s api.rb.
These call route, which starts as follows.
The Array construct will take anything and make it into an array, unless it’s already one. Which means that we can pass an array of methods to route. This is definitely part of Ruby magic, a C# or Java developer would strangle you for accepting object as a parameter and then transforming it into [object] _– but this is completely kosher in Ruby. But I digress, in order to route multiple methods for a single API we can invoke _route directly instead of get or post.