You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Writing Tests with Rack](#writing-tests-with-rack)
76
77
-[Writing Tests with Rails](#writing-tests-with-rails)
@@ -342,29 +343,6 @@ When an invalid `Accept` header is supplied, a `406 Not Acceptable` error is ret
342
343
option is set to `false`. Otherwise a `404 Not Found` error is returned by Rack if no other route
343
344
matches.
344
345
345
-
### HTTP Status Code
346
-
347
-
By default Grape returns a 200 status code for `GET`-Requests and 201 for `POST`-Requests.
348
-
You can use `status` to query and set the actual HTTP Status Code
349
-
350
-
```ruby
351
-
post do
352
-
status 202
353
-
354
-
if status ==200
355
-
# do some thing
356
-
end
357
-
end
358
-
```
359
-
360
-
You can also use one of status codes symbols that are provided by [Rack utils](http://www.rubydoc.info/github/rack/rack/Rack/Utils#HTTP_STATUS_CODES-constant)
361
-
362
-
```ruby
363
-
post do
364
-
status :no_content
365
-
end
366
-
```
367
-
368
346
### Accept-Version Header
369
347
370
348
```ruby
@@ -485,7 +463,7 @@ In the case of conflict between either of:
485
463
486
464
route string parameters will have precedence.
487
465
488
-
####Declared
466
+
### Declared
489
467
490
468
Grape allows you to access only the parameters that have been declared by your `params` block. It filters out the params that have been passed, but are not allowed. Consider the following API endpoint:
491
469
@@ -556,7 +534,7 @@ The returned hash is a `Hashie::Mash` instance, allowing you to access parameter
556
534
declared(params).user == declared(params)["user"]
557
535
```
558
536
559
-
####Include missing
537
+
### Include missing
560
538
561
539
By default `declared(params)` includes parameters that have `nil` values. If you want to return only the parameters that are not `nil`, you can use the `include_missing` option. By default, `include_missing` is set to `true`. Consider the following API:
562
540
@@ -735,7 +713,7 @@ params do
735
713
end
736
714
```
737
715
738
-
####Supported Parameter Types
716
+
### Supported Parameter Types
739
717
740
718
The following are all valid types, supported out of the box by Grape:
741
719
@@ -751,7 +729,7 @@ The following are all valid types, supported out of the box by Grape:
751
729
* Symbol
752
730
* Rack::Multipart::UploadedFile
753
731
754
-
####Custom Types
732
+
### Custom Types
755
733
756
734
Aside from the default set of supported types listed above, any class can be
757
735
used as a type so long as it defines a class-level `parse` method. This method
@@ -783,7 +761,7 @@ get '/stuff' do
783
761
end
784
762
```
785
763
786
-
####Validation of Nested Parameters
764
+
### Validation of Nested Parameters
787
765
788
766
Parameters can be nested using `group` or by calling `requires` or `optional` with a block.
789
767
In the above example, this means `params[:media][:url]` is required along with `params[:id]`,
@@ -806,7 +784,7 @@ params do
806
784
end
807
785
```
808
786
809
-
####Dependent Parameters
787
+
### Dependent Parameters
810
788
811
789
Suppose some of your parameters are only relevant if another parameter is given;
812
790
Grape allows you to express this relationship through the `given` method in your
@@ -1335,6 +1313,29 @@ Specify an optional path.
1335
1313
cookies.delete :status_count, path:'/'
1336
1314
```
1337
1315
1316
+
## HTTP Status Code
1317
+
1318
+
By default Grape returns a 200 status code for `GET`-Requests and 201 for `POST`-Requests.
1319
+
You can use `status` to query and set the actual HTTP Status Code
1320
+
1321
+
```ruby
1322
+
post do
1323
+
status 202
1324
+
1325
+
if status ==200
1326
+
# do some thing
1327
+
end
1328
+
end
1329
+
```
1330
+
1331
+
You can also use one of status codes symbols that are provided by [Rack utils](http://www.rubydoc.info/github/rack/rack/Rack/Utils#HTTP_STATUS_CODES-constant)
1332
+
1333
+
```ruby
1334
+
post do
1335
+
status :no_content
1336
+
end
1337
+
```
1338
+
1338
1339
## Redirecting
1339
1340
1340
1341
You can redirect to a new url temporarily (302) or permanently (301).
@@ -1607,7 +1608,7 @@ rescue_from RuntimeError, rescue_subclasses: false do |e|
1607
1608
end
1608
1609
```
1609
1610
1610
-
####Rails 3.x
1611
+
### Rails 3.x
1611
1612
1612
1613
When mounted inside containers, such as Rails 3.x, errors like "404 Not Found" or
1613
1614
"406 Not Acceptable" will likely be handled and rendered by Rails handlers. For instance,
@@ -2396,9 +2397,9 @@ specification and using the `PATH_INFO` Rack environment variable, using
2396
2397
`env["PATH_INFO"]`. This will hold everything that comes after the '/statuses/'
2397
2398
part.
2398
2399
2399
-
# Using Custom Middleware
2400
+
##Using Custom Middleware
2400
2401
2401
-
## Rails Middleware
2402
+
###Rails Middleware
2402
2403
2403
2404
Note that when you're using Grape mounted on Rails you don't have to use Rails middleware because it's already included into your middleware stack.
2404
2405
You only have to implement the helpers to access the specific `env` variable.
0 commit comments