mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Create grape integration documentation.
This commit is contained in:
parent
bcf3358524
commit
3d48a2fbf7
40
docs/howto/grape_integration.md
Normal file
40
docs/howto/grape_integration.md
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
The AMS grape formatter relies on the existence of `env['grape.request']` which is implemeted by `Grape::Middleware::Globals`. You can meet his dependency by calling it before mounting the endpoints.
|
||||||
|
|
||||||
|
In the simpliest way:
|
||||||
|
|
||||||
|
```
|
||||||
|
class API < Grape::API
|
||||||
|
# @note Make sure this is above you're first +mount+
|
||||||
|
use Grape::Middleware::Globals
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
or more like what is shown in current Grape tutorials:
|
||||||
|
|
||||||
|
```
|
||||||
|
module MyApi
|
||||||
|
class ApiBase < Grape::API
|
||||||
|
use Grape::Middleware::Globals
|
||||||
|
|
||||||
|
require 'grape/active_model_serializers'
|
||||||
|
include Grape::ActiveModelSerializers
|
||||||
|
|
||||||
|
mount MyApi::V1::ApiBase
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
You could meet this dependency with your own middleware. The invocation might look like:
|
||||||
|
|
||||||
|
```
|
||||||
|
module MyApi
|
||||||
|
class ApiBase < Grape::API
|
||||||
|
use My::Middleware::Thingamabob
|
||||||
|
|
||||||
|
require 'grape/active_model_serializers'
|
||||||
|
include Grape::ActiveModelSerializers
|
||||||
|
|
||||||
|
mount MyApi::V1::ApiBase
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
Loading…
Reference in New Issue
Block a user