2010-07-05

REST with Scala's Lift framework. Part 4 - DELETE

In my previous posts I described how to handle REST with Lift: GET, POST and PUT. Now it’s time for...


REST with Lift: DELETE


Delete is probably the most simple case. It only requires the object’s ID and it returns nothing (except for the HTTP code).

(I already did that with Spring 3.)


Retrieve the request


We are going to use DeleteRequest. For a more detailed description of this code, see the first post.

class Boot {
   def boot {
       // where to search snippet
       LiftRules.addToPackages("me.m1key")

       LiftRules.statelessDispatchTable.append {
           // ...
           case Req(List("rest", "dogs", dogId), _, DeleteRequest) =>
               () => DogsRestService.deleteDog(dogId)
       }
   }

}


Processing the request


This would normally be some sort of business logic...

    def deleteDog(dogId: String): Box[LiftResponse] = dogId match {
       case "1" => {
           Log.info("Deleting dog with ID: " + dogId)
           Full(OkResponse())
       }
       case _ => return Empty
   }

We return a Lift’s object - OkResponse.

Summary


It is no different (actually simpler) from the previous examples.

This completes the series! As said before, Spring 3 support is a lot better at this point, but we should wait to see what Lift 2.0 has to offer in this respect.

Download sample source code

3 comments:

  1. Tracking capabilities are rated at 3.93 points. This indicates good performance - tracking systems provide detailed and up-to-date information on most parameters of shipments, and also often overcome national (both political and linguistic) barriers and can be qualified as international tracking systems. http://www.confiduss.com/en/jurisdictions/austria/business/company-formation/

    ReplyDelete