I am a member of a team that is developing a mobile application using Flutter for the frontend and Laravel for the backend. My role is backend development i.e creating apis .We are also using MySQL as our database. I have created several APIs in Laravel and they are working fine most of the time. However, sometimes they return null and I am not sure what is causing this issue. I have only 11 months of experience in Laravel and I have searched online for possible solutions, but I could not find any definitive answer. I wonder if it is related to excessive resource consumption, database connectivity, or something else. The strange thing is that when I hit the same API again, it works fine. I am really confused and frustrated by this problem and I would appreciate any help or guidance from anyone who has faced a similar issue or knows how to fix it. Thank you for your time and attention.
Without knowing more about your application, we'd be guessing in the dark even more than you currently are.
My first suggestion, would be to instrument your application with more / better logging at the points where failures could be happening. For example, if it's one particular API or a specific group of them, maybe logging each time a collection is fetched to see how many items it's returning or whether the connection was successful.
Don't be afraid to throw a ton of Log::info(); statements all around if it'll help you narrow down the problem.
@nexxai Sometimes, when I call them from my mobile application, they return null instead of the expected data. However, when I test them with Postman, they work fine. This happens randomly with any API and I cannot reproduce it consistently. I have tried to debug my code and check the logs, but I could not find any clue or error. I am wondering if you have any idea what could be causing this problem or how to solve it. I would appreciate your help and advice. Thank you.
@usman9023 define "sometimes", if you try a ton of requests in a short period of time some of them might be timing out and some may be blocked by a rate limiter.
@usman9023 So you're saying that even when the API returns null, your logging shows that there is data that should be returned? As in you've correlated timestamps/requests from the Flutter app with the timestamps/requests from the Laravel app?