API route returns same result
Answered
Yellowhead catfish posted this in #help-forum
Yellowhead catfishOP
https://github.com/tookender/website/blob/main/src/app/api/doggo/route.ts
This API route should return a random doggo image, but instead it will always return the same one.
This API route should return a random doggo image, but instead it will always return the same one.
Answered by B33fb0n3
you would use the
export const dynamic = 'auto' method and set it to force-dynamic for example15 Replies
Yellowhead catfishOP
Here is the URl for anyone to try https://korino.dev/api/doggo
@Yellowhead catfish https://github.com/tookender/website/blob/main/src/app/api/doggo/route.ts
This API route should return a random doggo image, but instead it will always return the same one.
GET route handlers are cached by default.
You can opt out of caching by:
* Using the Request object with the GET method.
* Using any of the other HTTP methods.
* Using Dynamic Functions like cookies and headers.
* The Segment Config Options manually specifies dynamic mode.
You can opt out of caching by:
* Using the Request object with the GET method.
* Using any of the other HTTP methods.
* Using Dynamic Functions like cookies and headers.
* The Segment Config Options manually specifies dynamic mode.
Yellowhead catfishOP
wow quick response thanks
Using any of the other HTTP methods. wdym by that exactly? i just need it to return some dataor how do i Using the Request object with the GET method.
@Yellowhead catfish `Using any of the other HTTP methods.` wdym by that exactly? i just need it to return some data
with some other HTTP method I mean like "post, delete, put, ...". Of course that does not suite your case, so choose another opt out variant ^^
I recommend you the last one segment config:
https://nextjs.org/docs/app/building-your-application/routing/route-handlers#segment-config-options
https://nextjs.org/docs/app/building-your-application/routing/route-handlers#segment-config-options
Yellowhead catfishOP
do i just change "fetchCache"
like that you can opt out of caching and still using the same endpoint anf of course with GET
Yellowhead catfishOP
do i change it to "auto"?
@Yellowhead catfish do i just change "fetchCache"
you would use the
export const dynamic = 'auto' method and set it to force-dynamic for exampleAnswer
@B33fb0n3 you would use the export const dynamic = 'auto' method and set it to *force-dynamic* for example
Yellowhead catfishOP
yes this