redstone-dart / redstone

A metadata driven microframework for Dart.
http://redstone-dart.github.io/redstone
MIT License
342 stars 42 forks source link

Different functions all HTTP-methods #13

Closed akofoed closed 10 years ago

akofoed commented 10 years ago

I try to follow the principals here: http://www.restapitutorial.com/lessons/httpmethods.html

Coming from PlayFramework (Java) and Jersey (Java) I really like the fact that you can have different functions for each HTTP-method.

Ideally, I'd like to have my users class to look like this:

@app.Group('/v1/users')
class UserController {

    //POST /v1/users.json - to create a new user
    @app.Route('.json', methods: const [app.POST]) 
    createUser() {
        //...
    }
    //GET /v1/users.json - to get the list of users
    @app.Route('.json', methods: const [app.GET]) 
    getUsers() {
        //...
    }
    //GET /v1/users/1.json - to get one user
    @app.Route('/:id.json', methods: const [app.GET]) 
    getUser(int id) {
        //...
    }
    //UPDATE /v1/users/1.json - to update user ID 1
    @app.Route('/:id.json', methods: const [app.UPDATE]) 
    updateUser(int id) {
        //...
    }
    //DELETE /v1/users/1.json - to delete user ID 1
    @app.Route('/:id.json', methods: const [app.DELETE]) 
    deleteUser(int id) {
        //...
    }

}

How would that be possible? Let me know if I can help. I had a look at the competing Dart server frameworks and yours are the one closest how I think it should look. So again - Thanks :)

luizmineo commented 10 years ago

I did some code refactoring to allow multiple routes with same path and different HTTP methods. This change is available on the v0.5 branch.

Also, take a look at the issue #12 .

akofoed commented 10 years ago

Closing this as #12 solves it.

Thanks :+1:

/Anders