2

I'm trying to work out the best/most performant/easiest to maintain version for handling many different URLs in restlet.

eg, if I want to have an Item resource, is there a better way to do it than this?

router.attach("/items", ItemResource.class);
router.attach("/item/{itemid}", ItemResource.class);
router.attach("/items/list", ItemResource.ItemListResource.class);
router.attach("/items/weapons", ItemResource.WeaponListResource.class);
router.attach("/items/armours", ItemResource.ArmourListResource.class);
...

(I tried with having /items/{itemid}, but then /items/weapons etc could not be accessed.)

ItemResource then has @Get for fetching a single item, but also has @Put for saving an item when just /items is used. Something feels a bit wrong here... Is there a better way to have fetching/inserting/updating/listing for items in this case?

Also, this router.attach list is very long, 100 or so items. Since this has to be run through on every request it would probably be fairly slow. I know I can attach multiple routers together in a chain - but I can't find documentation on how to do this nicely. What's the best way to chain routers and keep them maintainable?

user456137
  • 97
  • 2
  • 5
  • I missed this question before: http://stackoverflow.com/questions/5682226/restlet-routing-nightmare?rq=1 - it answers the /items/ part of my question... – user456137 Nov 15 '12 at 09:13

1 Answers1

1

Just put the

router.attach("/item/{itemid}", ItemResource.class);

on the lowest part of the routing, since it will catch all path parameters, so before it matches everything, rout the typed path first. This should fix it based on my experience.

quarks
  • 33,478
  • 73
  • 290
  • 513