1

I am working on a React app which makes a lot of API calls, is there a middleware which can basically intercept all calls and console them similar to Multer for Express server.

In addition, I wonder if there is a general logger for events like errors, APIs, etc. in React.

Gaurav
  • 857
  • 3
  • 21
  • 29

1 Answers1

1

Although, you can see the request & response data in the Chrome Network Tab, but if you still want to see it logged in the console for some reason, Yes! there is a way.

If you are using axios to make API calls, you can use interceptors. Refer to this part of axios docs. You can do a console.log in the interceptor. Or check this answer.

If you are using fetch to make API calls, you can still define a custom function. Refer to this answer.

I think this will solve your problem. Good Luck!

Abhishek Kumawat
  • 780
  • 1
  • 10
  • 25