#pattern for route handling by accept header?

1 messages · Page 1 of 1 (latest)

coarse sky
#

using Next.js v15, app router, I've defined some routes with React FC's for viewing resource collections:

  • /things
  • /widgets
  • /objects

Nice table views with filtering, etc.

Now, I want to add "download CSV" to some of those, and if possible I'd like to use the same route. I wonder if there's an existing pattern for doing this kind of thing with Next? I wonder if I need to replace page.js with route.js but really I want both, and "somehow" choose between them using the HTTP Accept header values.
Am I thinking wrongly for considering these two views of the same resource to appear at the same URL path?

main sealBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

valid mauve
coarse sky
#

in another life I used a web framework that had a notion of "forwarding" requests (server-side) as an alternative to "redirecting" (which I think implies there would be an additional URL path to get the additional representation of the resource). Is there anything like that in Next.js? I want if possible to avoid exposing a new resource path to a different view of the same resource.

#

(Sorry, I don't mean so much to compare Next.js to web frameworks in other spaces, more just to explain where my thinking lies to see if I can get some help adjusting how I think about Next as a hypertext resource server)

valid mauve
#

you could technically set the middleware up so that if it sees the header and the pathname, it returns the csv immediately. i wouldn't do this though, but again, i wouldn't do whatever you are doing (react page component or raw response depending only on the request header) either

#

one of the rules upon which nextjs is designed on is: for any given pathname, it is expected to be used either by humans or bots. not both at the same time. if it's intended for humans, page.js. if it's intended for bots (returning raw response, returning machine-readable response, etc.), route.js