Skip to content

Commit c7b25ee

Browse files
committed
README formatting (indentation), organizational, and TOC cleanup
1 parent 683b7a1 commit c7b25ee

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

README.md

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- [Parameter Validation and Coercion](#parameter-validation-and-coercion)
3232
- [Supported Parameter Types](#supported-parameter-types)
3333
- [Custom Types](#custom-types)
34+
- [Validation of Nested Parameters](#validation-of-nested-parameters)
3435
- [Dependent Parameters](#dependent-parameters)
3536
- [Built-in Validators](#built-in-validators)
3637
- [Namespace Validation and Coercion](#namespace-validation-and-coercion)
@@ -59,7 +60,7 @@
5960
- [API Data Formats](#api-data-formats)
6061
- [RESTful Model Representations](#restful-model-representations)
6162
- [Grape Entities](#grape-entities)
62-
- [Hypermedia](#hypermedia)
63+
- [Hypermedia and Roar](#hypermedia-and-roar)
6364
- [Rabl](#rabl)
6465
- [Active Model Serializers](#active-model-serializers)
6566
- [Sending Raw or No Data](#sending-raw-or-no-data)
@@ -70,7 +71,7 @@
7071
- [Anchoring](#anchoring)
7172
- [Using Custom Middleware](#using-custom-middleware)
7273
- [Rails Middleware](#rails-middleware)
73-
- [Remote IP](#remote-ip)
74+
- [Remote IP](#remote-ip)
7475
- [Writing Tests](#writing-tests)
7576
- [Writing Tests with Rack](#writing-tests-with-rack)
7677
- [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
342343
option is set to `false`. Otherwise a `404 Not Found` error is returned by Rack if no other route
343344
matches.
344345

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-
368346
### Accept-Version Header
369347

370348
```ruby
@@ -485,7 +463,7 @@ In the case of conflict between either of:
485463

486464
route string parameters will have precedence.
487465

488-
#### Declared
466+
### Declared
489467

490468
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:
491469

@@ -556,7 +534,7 @@ The returned hash is a `Hashie::Mash` instance, allowing you to access parameter
556534
declared(params).user == declared(params)["user"]
557535
```
558536

559-
#### Include missing
537+
### Include missing
560538

561539
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:
562540

@@ -735,7 +713,7 @@ params do
735713
end
736714
```
737715

738-
#### Supported Parameter Types
716+
### Supported Parameter Types
739717

740718
The following are all valid types, supported out of the box by Grape:
741719

@@ -751,7 +729,7 @@ The following are all valid types, supported out of the box by Grape:
751729
* Symbol
752730
* Rack::Multipart::UploadedFile
753731

754-
#### Custom Types
732+
### Custom Types
755733

756734
Aside from the default set of supported types listed above, any class can be
757735
used as a type so long as it defines a class-level `parse` method. This method
@@ -783,7 +761,7 @@ get '/stuff' do
783761
end
784762
```
785763

786-
#### Validation of Nested Parameters
764+
### Validation of Nested Parameters
787765

788766
Parameters can be nested using `group` or by calling `requires` or `optional` with a block.
789767
In the above example, this means `params[:media][:url]` is required along with `params[:id]`,
@@ -806,7 +784,7 @@ params do
806784
end
807785
```
808786

809-
#### Dependent Parameters
787+
### Dependent Parameters
810788

811789
Suppose some of your parameters are only relevant if another parameter is given;
812790
Grape allows you to express this relationship through the `given` method in your
@@ -1335,6 +1313,29 @@ Specify an optional path.
13351313
cookies.delete :status_count, path: '/'
13361314
```
13371315

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+
13381339
## Redirecting
13391340

13401341
You can redirect to a new url temporarily (302) or permanently (301).
@@ -1607,7 +1608,7 @@ rescue_from RuntimeError, rescue_subclasses: false do |e|
16071608
end
16081609
```
16091610

1610-
#### Rails 3.x
1611+
### Rails 3.x
16111612

16121613
When mounted inside containers, such as Rails 3.x, errors like "404 Not Found" or
16131614
"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
23962397
`env["PATH_INFO"]`. This will hold everything that comes after the '/statuses/'
23972398
part.
23982399

2399-
# Using Custom Middleware
2400+
## Using Custom Middleware
24002401

2401-
## Rails Middleware
2402+
### Rails Middleware
24022403

24032404
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.
24042405
You only have to implement the helpers to access the specific `env` variable.

0 commit comments

Comments
 (0)