Skip to content

Commit eaeb55e

Browse files
committed
updates changelog and readme with HTTP 405 (Method Not Allowed) response details
1 parent eaa2219 commit eaeb55e

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

CHANGELOG.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Fixes
2020
* [#181](https://github.com/intridea/grape/pull/181): Fix: Corrected JSON serialization of nested hashes containing `Grape::Entity` instances - [@benrosenblum](https://github.com/benrosenblum).
2121
* [#203](https://github.com/intridea/grape/pull/203): Added a check to `Entity#serializable_hash` that verifies an entity exists on an object - [@adamgotterer](https://github.com/adamgotterer).
2222
* [#208](https://github.com/intridea/grape/pull/208): `Entity#serializable_hash` must also check if attribute is generated by a user supplied block - [@ppadron](https://github.com/ppadron).
23+
* [#252](https://github.com/intridea/grape/pull/252): Resources that don't respond to a requested HTTP method return 405 (Method Not Allowed) instead of 404 (Not Found) [@simulacre](https://github.com/simulacre)
2324

2425
0.2.1 (7/11/2012)
2526
=================

README.markdown

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,50 @@ redirect "/new_url"
411411
redirect "/new_url", :permanent => true
412412
```
413413

414+
## Allowed Methods
415+
416+
When you add a route for a resource, a route for the HTTP OPTIONS
417+
method will also be added. The response to an OPTIONS request will
418+
include an Allow header listing the supported methods.
419+
420+
``` ruby
421+
class API < Grape::API
422+
get '/counter' do
423+
{ :counter => Counter.count }
424+
end
425+
426+
params do
427+
requires :value, :type => Integer, :desc => 'value to add to counter'
428+
end
429+
put '/counter' do
430+
{ :counter => Counter.incr(params.value) }
431+
end
432+
end
433+
```
434+
435+
``` shell
436+
curl -v -X OPTIONS http://localhost:3000/counter
437+
438+
> OPTIONS /counter HTTP/1.1
439+
>
440+
< HTTP/1.1 204 No Content
441+
< Allow: OPTIONS, GET, PUT
442+
```
443+
444+
445+
If a request for a resource is made with an unsupported HTTP method, an
446+
HTTP 405 (Method Not Allowed) response will be returned.
447+
448+
``` shell
449+
curl -X DELETE -v http://localhost:3000/counter/
450+
451+
> DELETE /counter/ HTTP/1.1
452+
> Host: localhost:3000
453+
>
454+
< HTTP/1.1 405 Method Not Allowed
455+
< Allow: OPTIONS, GET, PUT
456+
```
457+
414458
## Raising Exceptions
415459

416460
You can abort the execution of an API method by raising errors with `error!`.

0 commit comments

Comments
 (0)