near to couple of thousands requests to API and I need to make it robust and effective, what shuuld I avoid doing? Does okhttp library fits to my case or should I consider using something else?
Thanks
Few things I can think of right away: - rate limiting. If it's 3rd party API, then most likely it is rate limited. Learn all the limits of the API, and tune your code to not spam it with requests. - prepare for failure. Think of what you should do if your recive non-200s. It greatly depends on what exactly you're developing. Typical approaches to start with: — "circuit breaker", basically means "if it failed several times in a row, stop spamming it, give it some time, and continue later" — "retry" (usually with some backoff strategy, typical one is "exponential backoff"), means "if it failed, retry a little bit later" - depending on what you're developing, if your app may stop/restart/get killed/etc., and after restart you need to continue from the last successful call, you'll need to persist state. Depending on what you're developing, it may be a simple file, or it may be a record in DB, whatever is easier.
Thank you for the advices! Rate limit is already one of the things that I have caught 😅
Doesn't Java have a built-in HTTP client at java.net.http?
Yes, it does, but I have adopted the project from other developer. It already had code with okhttp library used. I have a controller that receives some parameters, after that in the service layer I'm sending info according to the input to 3rd party API. Everything works ok once program receives only 1 request, but with multiple requests it's getting weird behavior where requests starting not get response at all, and one other parts of service layer is POST uploading of files to AWS S3 is where I found the request rate limit.
The built-in http client is way too basic, and hard to use. You need too much boilerplate to just send a post request. Plus it's synchronous. It's fine for simple tasks, but for making http requests routinely it's not a good fit.
Sounds like concurrency issues. If you shared some code, I believe I could help
I found the problem later in the day, it again was a request rate limit. The API I'm communicating with just handles that in a weird way, not like AWS, that's why it was confusing to me and I was assuming that it could be some concurrency things. But anyways thank you for the response
Обсуждают сегодня