Should static parameters in an API be part of each method?
- by jschoen
I am currently creating a library that is a wrapper for an online API. The obvious end goal is to make it as easy for others to use as possible. As such I am trying to determine the best approach when it comes to common parameters for the API.
In my current situation there are 3 (consumer key, consumer secret, and and authorization token). They are essentially needed in every API call. My question is should I make these 3 parameters required for each method or is there a better way.
I see my current options as being:
Place the parameters in each method call
public ApiObject callMethod(String consumerKey, String consumerSecret, String token, ...)
This one seems reasonable, but seems awfully repetitive to me.
Create a singleton class that the user must initialize before calling any api methods. This seems wrong, and would essentially limit them to accessing one account at a time via the API (which may be reasonable, I dunno).
Make them place them in a properties file in their project. That way I can load the properties that way and store them. This seems similar to the singleton to me, but they would not have to explicitly call something to initialize these values.
Is there another option I am not seeing, or a more common practice in this situation that I should be following?