intridea/grape — pull request #512 by dblock (2013-11-21 19:41:42+00:00)
Title: Don't create Grape::Request multiple times.

For a simple API call we're manufacturing the `Grape::Request` object many times.

* lib/grape/middleware/formatter.rb:102:in `format_from_extension' (6 times)
* lib/grape/endpoint.rb:380:in `new'
* once if you call `.request` in the API.

The first one could easily be fixed by storing @request ||= Grape::Request.new, but each middleware and API call would still continue to creating its own request object if it needed one.

This PR attempts to solve that cleanly:

* Remove `Base.request`.
* Decouple the formatter middleware from using a `Grape::Request` from the base class, use its own.
* Decouple the oauth2 middleware from using a `Grape::Request` from the base class, use its own.
* Assign request, headers and params in endpoint on call.

Will leave this open for a bit for some comments, /cc: @mbleigh.