405 when multiple HTTP methods with same path in ratpack.groovy

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

405 when multiple HTTP methods with same path in ratpack.groovy

Neeraj
Hi,

I have been running into a very basic issue trying to setup a quick POC to port existing grails app to ratpack.

Consider the following ratpack.groovy snippet (modified from the gorm-mongo example app  on github).

ratpack {
    modules {
        register(new GormModule('domains'))
    }

    handlers {
        prefix('author') {
            post(){
                new Author(name:"The Stand").save(flush:true)
                response.send "created"
            }
            get(){
                def list = Author.collection.find()
                response.send "application/json", JSON.serialize(list)
            }
        }
    }
}


All POST to  ../author work successfully.
Any GET to the url ../author fails with a 405.

If we flip the order of the 'post' and 'get' handlers in ratpack.groovy,  all GET requests will succeed, but
POST will fail with 405.

Is this user error ? or is it a regression bug ?


Reply | Threaded
Open this post in threaded view
|

Re: 405 when multiple HTTP methods with same path in ratpack.groovy

Luke Daley
Administrator
If you want to have the one URL respond to multiple methods, you have to do something different:

Here's an example: https://github.com/ratpack/ratpack/blob/master/ratpack-core/src/test/groovy/org/ratpackframework/path/PathAndMethodRoutingSpec.groovy#L61
Reply | Threaded
Open this post in threaded view
|

Re: 405 when multiple HTTP methods with same path in ratpack.groovy

Neeraj
awesome ! that fixed the issue. Thank you for the quick response.

It would be user friendly to support the DSL i was attempting to use.... not sure how severe the associated changes would be.
Reply | Threaded
Open this post in threaded view
|

Re: 405 when multiple HTTP methods with same path in ratpack.groovy

Luke Daley
Administrator
Supporting the kind of DSL you were trying to use is very difficult in an async processing environment, which is what Ratpack is.

I'm still looking for more user friendly solutions, but what I pointed you to is the way to do it right now.