Exporting a deeply nested series of routes
Unanswered
Large garden bumble bee posted this in #help-forum

Large garden bumble beeOP
Hello, I am exporting a client which will be used by a bunch of Next.js apps. I want to distribute a "proxy" over an SDK I have, which may be deeply nested. It would look like this:
These are basically set up to use my SDK and extract values from the NextRequest. As an example, let's say I want to look at
I want to have this as a package where people can simply import it and somehow use it in a way where they can set up an API key. As an example, maybe like this:
How would this be done? Can it be done?
./src/app/api
├── film
│ ├── [id]
│ │ └── route.ts
│ └── route.ts
└── review
├── [id]
│ └── route.ts
└── route.ts
These are basically set up to use my SDK and extract values from the NextRequest. As an example, let's say I want to look at
app/api/films
export async function GET(request: NextRequest) {
const limit = request.nextUrl.searchParams.get('limit');
const offset = request.nextUrl.searchParams.get('offset');
const data = await client.films.findMany({ limit, offset });
return NextResponse.json(data);
}
I want to have this as a package where people can simply import it and somehow use it in a way where they can set up an API key. As an example, maybe like this:
const routeHandlers = createRouteHandlers(process.env.FILM_DB_API_KEY);
export routeHandlers;
How would this be done? Can it be done?
1 Reply

@Large garden bumble bee Hello, I am exporting a client which will be used by a bunch of Next.js apps. I want to distribute a "proxy" over an SDK I have, which may be deeply nested. It would look like this:
typescript
./src/app/api
├── film
│ ├── [id]
│ │ └── route.ts
│ └── route.ts
└── review
├── [id]
│ └── route.ts
└── route.ts
These are basically set up to use my SDK and extract values from the NextRequest. As an example, let's say I want to look at `app/api/films`
typescript
export async function GET(request: NextRequest) {
const limit = request.nextUrl.searchParams.get('limit');
const offset = request.nextUrl.searchParams.get('offset');
const data = await client.films.findMany({ limit, offset });
return NextResponse.json(data);
}
I want to have this as a package where people can simply import it and somehow use it in a way where they can set up an API key. As an example, maybe like this:
typescript
const routeHandlers = createRouteHandlers(process.env.FILM_DB_API_KEY);
export routeHandlers;
How would this be done? Can it be done?

yeah it can be done with an API like this:
your
export const GET = createRouterHandler(process.env.FILM_DB_API_KEY)
your
createRouterHandler
function would then return a function which receives the request
as the parameter