Parsing out multiple parameters

40 views
Skip to first unread message

Prashanth Acharya

unread,
May 2, 2016, 5:09:17 AM5/2/16
to spray.io User List
Please pardon me if this is something real simple that I missed, but I did RTFM, and also experiment extensively

what im trying to do is something along the lines of


POST /garages/:gid/cars/:cid/repairjob with complex json payload {"repair.. details.. here..."} should initiate a new repair job

GET /garages/:gid/cars/:cid should get me the repair history for this car

PATCH /garages/:gid/cars/:cid/repairjobs/:rjid with some kind of json like {"eta":"10 days"} should just update that one field in the repair job

GET /garages/:gid/cars/:cid/repairjobs/:rjid should get me the complete repair details

How can I wire this up?

note that :gid refers to a garage id, which is a UUID, ditty for car id :cid and repair job id :rjid

Prashanth Acharya

unread,
May 2, 2016, 5:19:32 AM5/2/16
to spray.io User List
im using spray 1.3.3

Age Mooij

unread,
May 2, 2016, 5:28:27 AM5/2/16
to spray...@googlegroups.com
It's all there in the spray-routing docs but I can understand it's hard to put stuff together. There's quite some open sources spray-routing apps on github and examples on SO that might help you get a hang of how to combine stuff.

Here's a quick sketch, uncompiled and untested, of what your code should look like:

pathPrefix("garages" / JavaUUID / "cars" / JavaUUID) { (garageId, carId) =>
  path("repairjob") & post {
    entity(as[RepairJob]) { job =>
      // should initiate a new repair job
    }
  } ~
  pathEndOrSingleSlash & get {
    // should get me the repair history for this car
  } ~
  path("repairJobs" / JavaUUID) { rpjId =>
    patch {
      entity(as[RepairJobUpdate]) { update =>
        // should just update that one field in the repair job
      }
    } ~
    get {
      // should get me the complete repair details
    }
  }
}

Hope this helps
Age


-- 
You received this message because you are subscribed to the Google Groups "spray.io User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spray-user+...@googlegroups.com.
Visit this group at https://groups.google.com/group/spray-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/bdce28da-225a-489f-abbf-21217627768e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Prashanth Acharya

unread,
May 2, 2016, 2:18:32 PM5/2/16
to spray.io User List
Thanks a Bunch. Will try this approach. 


On Monday, May 2, 2016 at 2:09:17 AM UTC-7, Prashanth Acharya wrote:
Reply all
Reply to author
Forward
0 new messages