Support setting of createdId via annotations

Issue #10 resolved
Anders Holmgren repo owner created an issue

Comments (8)

  1. Michael Goodness

    I was this close to filing an issue to request setting the Location header by annotation. Then I found (in bindings.dart, line 283):

     // TODO: support annotation like @CreatedId(#identifier)
    

    Safe to say that's what you have in mind?

  2. Anders Holmgren Account Deactivated

    At the moment it has two cases:

    1. You do a PUT when creating a new instance of your resource, in which case it takes the request URL as the location
    2. You do a POST and the object you return has a field called id, in which case it does requestUrl/$id

    For the POST case I want to allow you to be able to use a field called something other than id so I was thinking an annotation for that. E.g. if you do

    POST /foo
    

    and your handler returns a Foo class like

    class Foo {
       String fooPK;
    
       // other fields
    }
    

    and fooPK is the unique key for that resource (i.e. you want the location to be /foo/${myFoo.fooPK}) then you could do a handler like

    @ CreatedId(#fooPK)
    Foo createFoo(String name) {
      // create a Foo somehow with a unique fooPK (e.g. save it into the DB and have the db auto generate the value)
      return foo;
    }
    

    Is that the kind of thing you are looking for or do you want to set the location manually (or both)?

  3. Michael Goodness

    You've described my use case exactly. Being able to to specify the unique key by annotation would be perfect - no need to set the location manually.

  4. Anders Holmgren Account Deactivated

    cool I'll add something fairly soon. Likely add something to the ResponseHeaders annotation e.g.

    class ResponseHeaders {
      ...
      Symbol idField;
    }
    
  5. Log in to comment