jeudi 6 février 2020

API client class library design

I'm creating a class library to be reused through multiple projects. The class library is an API client wrapper. I've created class with private fields (basic auth, httpclient, requests headers list, base url) the fields values are set in class constructor. Then I've created couple of methods for different API methods. As for different API methods second part of url vary (including some dynamic parts e.g. "/user/{userid}/files") I'm not sure how to approach these changes:

  1. would it be better to pass the second part of the url to every single method as an argument
  2. or pass it as an argument to class constructor (similar to headers dictionary)
  3. or maybe hardcode it in every method.

Is there any other approach I haven't consider yet?

Aucun commentaire:

Enregistrer un commentaire