EasyPost / easypost-java

EasyPost Shipping API Client Library for Java
https://easypost.com/docs/api
MIT License
54 stars 37 forks source link

Drop automagical endpoint calculation, replace with explicit endpoints #230

Closed nwithan8 closed 1 year ago

nwithan8 commented 1 year ago

Description

I've never been a fan of how this (and some of our other libraries) determine what endpoint to hit in our API by basically taking the name of the class, figuring out how to make it plural and then lowercasing it. The "class URL" and "instance URL" utility functions are clunky, do unnecessary reflection, are hard to follow, and are simply begging to break one day in the future simply because a class name does not one-to-one match an endpoint on the API.

Instead, as was done in the C# library during its rewrite last year, this "automagical" utility was removed and instead replaced with explicit endpoint strings. This not only returns transparency to what endpoint is being hit on each function, but also dramatically improves readability of our code.

This PR also makes minor tweaks to how the requestor function operates under-the-hood, mainly by containing client API base and version information solely to that class. Previously, the whole URL (including base and API version) were determined in each service. Now, that calculation is pushed downstream into one location inside the actual request function. This restructuring also allows for the introduction of API version override on a per-request basis, making "beta" endpoints more obvious and meaning less changes needed when a beta features migrates to general availability and no longer needs to hit the "beta" API version.

Testing

Pull Request Type

Please select the option(s) that are relevant to this PR.