Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Advice on 3rd party API calls, rate limiting

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all!
I am totally new here on the forum, so if i write something in the wrong place / anything else, please let me know.

Currently i am putting together a small application for sending text messages through a 3'rd party API that has the connection to the cellular towers.
The application works in the sense that it can send an text message and get a status, but i would like to improve my overall skills and so i am (if possible) seekind advice.

1. My 3'rd party vendor does not have a library that i can use with my application, to check statuses of a API call and so on.
Are there any generalised libraries available for Java that makes working with 3'rd party API's through GET/POST easier than creating everything yourself?

2. My 3'rd party vendor does not rate limit any incoming requests, so in theory if i sent 10.000 SMS's within 1 minut because of a loop gone wrong, they would just say "Thank you very much for using our service, please pay XXXX$"
Besides using common sense, creating good code, adhere best practices, are there any Java libraries that i can use to help me or are there some pattern / something else i can look into?

Thanks in advance to all!
Best regards.
 
Saloon Keeper
Posts: 7185
166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you mention GET and POST I'm assuming that you're makin HTTP connections to that service. You didn't say how you're making connections now, but a library like OkHttp takes some of pain out of Java HTTP networking.
 
Drenriza Housen
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:Since you mention GET and POST I'm assuming that you're makin HTTP connections to that service. You didn't say how you're making connections now, but a library like OkHttp takes some of pain out of Java HTTP networking.



Hi Tim! Thanks for your reply.
Yes you are absolutely correct, it's a HTTP connection

Thanks for the suggestion! I will definitely look into that.
 
Saloon Keeper
Posts: 13431
303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Drenriza Housen wrote:Are there any generalised libraries available for Java that makes working with 3'rd party API's through GET/POST easier than creating everything yourself?


Yes, Java 11 has the HttpClient class. However, if the API you are consuming is RESTful, you may find it easier to use the JAX-RS Client API. For instance, imagine the server side API looks like this:

You may then write a client such as this:

To use the JAX-RS client API, you must have the following dependency:

If the web service communicates with XML you will want the following dependency:

At runtime you need the following dependencies:

Again, if the web service uses XML to communicate, you need the following runtime dependencies:


Besides using common sense, creating good code, adhere best practices, are there any Java libraries that i can use to help me or are there some pattern / something else i can look into?.


Test your code very well. Make sure to write unit-tests exhaustively, and throw in some integration tests for good measure. That way you may catch mistakes before they get to a production system. As an added measure, you might route your outgoing requests through a proxy that throttles the number of requests for you, and also notifies you of excessive amounts of requests.
 
Drenriza Housen
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stephan van Hulst!

Thanks for your reply! I will definitely look into your suggestions.

I had not thought about putting a proxy infront of the application, that ofcourse makes alot of sense.
A solution here could be a Nginx proxy with a rate limit and burst configuration connected with Zabbix for monitoring and notification.

Thanks for the great feedback.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic