File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,36 @@ class API < Grape::API
122122end
123123````
124124
125+ ## Cookies
126+
127+ You can set, get and delete your cookies very simply using ` cookies ` method:
128+
129+ ```` ruby
130+ class API < Grape ::API
131+ get ' /counter' do
132+ cookies[:counter ] ||= 0
133+ cookies[:counter ] += 1
134+ { :counter => cookies[:counter ] }
135+ end
136+
137+ delete ' /counter' do
138+ { :result => cookies.delete(:counter ) }
139+ end
140+ end
141+ ````
142+
143+ To set more then value use hash-based syntax:
144+
145+ ```` ruby
146+ cookies[:counter ] = {
147+ :value => 0 ,
148+ :expires => Time .tomorrow,
149+ :domain => ' .example.com' ,
150+ :path => ' /'
151+ }
152+ cookies[:counter ][:value ] += 1
153+ ````
154+
125155## Raising Errors
126156
127157You can raise errors explicitly.
You can’t perform that action at this time.
0 commit comments