I have some automated RESTful API tests in Java. They use a proprietary Java library (restLibOne
) to make API calls. The proprietary library is similar in concept to REST Assured, but vastly different from it in terms of how it makes API calls. Now, there is another proprietary library, restLibTwo
, that will replace restLibOne
and is vastly different from it. Who knows,
in the future there may be yet another replacement.
I need to convert the code to use restLibTwo
instead of restLibOne
. I am not sure how to approach this project but I have an idea. I want to start by making some "generic" class that represents how REST API calls are made. Then, the functions in this class will use any library to make those calls. For example:
class GenericApiCaller {
public static MyResponseObject doGet(MyRequestObject request){
// 1 - use any library to make api call by using the data in request object.
// 2 - cast result of 1st step into MyResponseObject response.
// 3 - return response.
}
public static MyResponseObject doPost(MyRequestObject request){
}
// etc...
}
class MyRequestObject {
// It stores the information needed to make a request to any rest service - url, body, headers etc.
// Rest assured or whichever library you like can pick up those information from this object.
}
The problem is that I don't know how to design functions to make API calls. I don't know what inputs are needed to make API calls besides simple inputs like URL, headers, method, body, etc., so I don't know what arguments my API call making functions should have.
Then, I don't know what all things a response must have besides the simple ones like code, headers, body, etc., so, I don't know what kind of object should be returned by my API call making functions.
Is there already a generic class/code that does what I want? If not, then how should I go about designing my own class? Is this project best given to someone who is an expert in API automation?