Skip to content

Commit 841f53f

Browse files
committed
Update README - subscribe to hooks
1 parent 4e69c56 commit 841f53f

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

README.md

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@
139139
- [Reloading in Rails Applications](#reloading-in-rails-applications)
140140
- [Performance Monitoring](#performance-monitoring)
141141
- [Active Support Instrumentation](#active-support-instrumentation)
142-
- [endpoint_run.grape](#endpoint_rungrape)
143-
- [endpoint_render.grape](#endpoint_rendergrape)
144-
- [endpoint_run_filters.grape](#endpoint_run_filtersgrape)
145-
- [endpoint_run_validators.grape](#endpoint_run_validatorsgrape)
146-
- [format_response.grape](#format_responsegrape)
142+
- [Hook points](#hook-points)
143+
- [endpoint_run.grape](#endpoint_rungrape)
144+
- [endpoint_render.grape](#endpoint_rendergrape)
145+
- [endpoint_run_filters.grape](#endpoint_run_filtersgrape)
146+
- [endpoint_run_validators.grape](#endpoint_run_validatorsgrape)
147+
- [format_response.grape](#format_responsegrape)
148+
- [Subscribe to hooks](#subscribe-to-hooks)
147149
- [Monitoring Products](#monitoring-products)
148150
- [Contributing to Grape](#contributing-to-grape)
149151
- [Security](#security)
@@ -4125,35 +4127,36 @@ See [StackOverflow #3282655](http://stackoverflow.com/questions/3282655/ruby-on-
41254127

41264128
Grape has built-in support for [ActiveSupport::Notifications](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) which provides simple hook points to instrument key parts of your application.
41274129

4128-
The following are currently supported:
41294130

4130-
#### endpoint_run.grape
4131+
#### Hook points
4132+
The following hook points are currently supported:
4133+
##### endpoint_run.grape
41314134

41324135
The main execution of an endpoint, includes filters and rendering.
41334136

41344137
* *endpoint* - The endpoint instance
41354138

4136-
#### endpoint_render.grape
4139+
##### endpoint_render.grape
41374140

41384141
The execution of the main content block of the endpoint.
41394142

41404143
* *endpoint* - The endpoint instance
41414144

4142-
#### endpoint_run_filters.grape
4145+
##### endpoint_run_filters.grape
41434146

41444147
* *endpoint* - The endpoint instance
41454148
* *filters* - The filters being executed
41464149
* *type* - The type of filters (before, before_validation, after_validation, after)
41474150

4148-
#### endpoint_run_validators.grape
4151+
##### endpoint_run_validators.grape
41494152

41504153
The execution of validators.
41514154

41524155
* *endpoint* - The endpoint instance
41534156
* *validators* - The validators being executed
41544157
* *request* - The request being validated
41554158

4156-
#### format_response.grape
4159+
##### format_response.grape
41574160

41584161
Serialization or template rendering.
41594162

@@ -4162,6 +4165,27 @@ Serialization or template rendering.
41624165

41634166
See the [ActiveSupport::Notifications documentation](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) for information on how to subscribe to these events.
41644167

4168+
#### Subscribe to hooks
4169+
4170+
Once subscribed to the instrumentation, you can intercept the events reported above.
4171+
4172+
```
4173+
ActiveSupport::Notifications.subscribe(/<api_path>/) do |name, start, finish, id, payload|
4174+
# your code to intercept the notification
4175+
end
4176+
```
4177+
4178+
The request data, the API’s internal data, and the response can be retrieved from the payload.
4179+
4180+
You can use `payload.fetch(:endpoint)` or directly `payload[:endpoint]`.
4181+
4182+
The `:endpoint` contains the data currently being processed.
4183+
4184+
The endpoint provides access to the following attributes:
4185+
`body`, `request`, `params`, `headers`, `cookies`, `response_cookies`
4186+
4187+
For example, `payload[:endpoint].body` provides the current state of the response
4188+
41654189
### Monitoring Products
41664190

41674191
Grape integrates with following third-party tools:

0 commit comments

Comments
 (0)