0

I want to make a request to a logging service after serving the request. For eg you hit an endpoint '/hello' i want to increment count in redis but after serving the request. Something similar to res.on('final') in express.js.

I tried searching the docs to something similar to res.on('final') but can't find any solution.

No Name
  • 98
  • 1
  • 11

1 Answers1

0

Nuxt is usinig ofetch library. You can add a callback after the call is done and response is parsed https://github.com/unjs/ofetch#onresponse-request-options-response-

Also usable within useFetch() wrapper see in examples https://nuxt.com/docs/api/composables/use-fetch#example

If you consider using $fetch or any composable as wrapper like useFetch() consider this

We recommend to use useFetch or useAsyncData + $fetch to prevent double data fetching when fetching the component data.

https://nuxt.com/docs/api/utils/dollarfetch

devnik
  • 341
  • 3
  • 11
  • Actually i meant that I created the api and once the API have served the client I want to log the request. some thing like [res.on('finish')](https://stackoverflow.com/a/38573060/11485023) but in nuxt. – No Name Jun 22 '23 at 15:55