oak icon indicating copy to clipboard operation
oak copied to clipboard

Params property in Context type

Open marcosadriano05 opened this issue 3 years ago • 2 comments

I have been make an adapter to integrate my controllers with Oak Router, but i can't get the route params because Context type don't have params property. For exemple:

On adpater, instructions like this works: const body = context.request.body({ type: "json"}).value const headers = context.request.headers

But the route params don't work: const params = context.params don't work because context: Context don't have params property.

The adapter is like: const adapter => (controller: Controller) => (context: Context) => {}

And its use on router definition, for exemple: router.get("/car/:id", adapter(getCarController())

Any sugestions to resolve this problem? My sugestion is to implement params property in Context type too.

marcosadriano05 avatar Apr 29 '22 01:04 marcosadriano05

I had the same issue :disappointed_relieved:

abdulrahman1s avatar May 12 '22 02:05 abdulrahman1s

okay solved by using the RouterMiddleware instead of Middleware

abdulrahman1s avatar May 12 '22 02:05 abdulrahman1s

Use like this:

import { RouterContext } from 'https://deno.land/x/[email protected]/mod.ts';

const adapter => (controller: Controller) => (context: RouterContext<strig>) => {}

It works for me :)

sonickseven avatar Mar 28 '23 04:03 sonickseven

Use like this:

import { RouterContext } from 'https://deno.land/x/[email protected]/mod.ts';

const adapter => (controller: Controller) => (context: RouterContext<strig>) => {}

It works for me :)

Thanks!

(only add some notes, showing my custom case and may be it will be useful for someone) if i correctly understand, it works as type-checker.

try to use with incorrect route:

image

change to correct spelling:

image

kindkitchen avatar Oct 31 '23 20:10 kindkitchen