How to re-route Post when it should be a Put?

3 views
Skip to first unread message

wer vetra

unread,
Apr 18, 2016, 9:42:17 AM4/18/16
to spray.io User List
Other than proxyDirectives, which I understand never made it in to spray, is there other built-in functionality to re-route a Post request to become a Put request instead? 

Consider the common use example:


Someone goes to Post a new record, unaware of all the specific discriminating identifiers (e.g. the record's database primary key ID, or possibly other unique key constraints) and it turns out that the information they posted was in fact a duplicate. So, the database returns a key constraint violation error and your route is now left with 2 decisions:

1) return the error to the user and leave it up to them to instead perform an update action via a Put request (assuming the route returns the specific record for them to reference)
2) intelligently presume the user was intending to do an update in the first place, and that they aren't keeping track of database primary keys / constraints (pretty likely) and then duplicate the Put request code inside your Post.


I really want to do 2), but the problem is I now have update (Put) logic in both my Put and Post (e.g.: if the post fails attempt Put update on the database row that the key violation occurred on). What I would love is to simply re-route the request to the Put directive already defined. Is there a way to do that? Possible a Rejection that tries something else before finally failing?


What is logically disorganized about what I seek? Or, is it currently implemented in the framework as a possibility? Thanks!
Reply all
Reply to author
Forward
0 new messages