itty-durable icon indicating copy to clipboard operation
itty-durable copied to clipboard

How do you pass the request object and Params into the middleware/services?

Open repzip opened this issue 3 years ago • 6 comments

Great module... I have spent a good bit of time trying to figure out how to pass params and request object into methods of the Durable Object?

Any help would be great.

Thanks.

repzip avatar Jun 09 '21 08:06 repzip

I spent few moments with same thing and came up with this:

import {
   [...]
  withParams,
  withContent,
} from "itty-router-extras";

[...]

router.post("/test/:id", withParams, withContent,
  async({content,DurableObject,id}) => {
    console.log(`This is ${content} with id ${id}`);
    const object = DurableObjects.get(id);
    return object.toJSON();
});

savikko avatar Jun 10 '21 17:06 savikko

Hold on, let me dust the cobwebs off! I know there's a way because this was obv a common use-case (have to be able to use other KV/durables from within a durable, for instance) :)

kwhitley avatar Jun 11 '21 16:06 kwhitley

I had to shelve this temporarily (I'll be back, because I need it) for a death in the family :'(

kwhitley avatar Jun 11 '21 16:06 kwhitley

Terribly sorry to hear that, my condolences. I will mess around with it today and try figure it out.

repzip avatar Jun 12 '21 09:06 repzip

Post methods dont work?

subhendukundu avatar Jul 24 '22 18:07 subhendukundu

Post methods dont work?

Just in example, route with withDurable - is 'get' - just change it to 'all' ;)

router .all('*', withDurables())

sinitsa avatar Aug 01 '22 06:08 sinitsa