Let's dive into that and create a new empty class. It depends where you would like to use this class so choose the respective module based on your case. I chose module 4_World
classExampleApi{ // Suggestion is to cache the api reference (do not create new instance for each call) protectedrefCRDTN_RestApiWrapper m_RestApi;};
As you can see, I just made an empty class with a cached reference to a RestApi wrapper class instance. Let's add the constructor to the class and setup the API upon the constructing our class ExampleApi
classExampleApi{ // Suggestion is to cache the api reference (do not create new instance for each call) protectedrefCRDTN_RestApiWrapper m_RestApi;voidExampleApi() { // https://my-backend-serverstring url =""; // Use some endpoint you need to call request on m_RestApi =newCRDTN_RestApiWrapper(url); }};
Using GET method
// Instantiate the api instance for the URL autoptr CRDTN_RestApiWrapper m_RestApi =newCRDTN_RestApiWrapper("https://my-backend-server");// Using callback eventsm_RestApi.ExecuteRequest("/endpoint","GET","");
Using POST method
RestApiResponse<string> requestData =newRestApiResponse<string>();requestData.requestType=typename.EnumToString(RestApiRequestType,RestApiRequestType.AUTH_TEST);requestData.uniqueId="testUser";string data =JsonFileLoader<RestApiResponse<string>>.JsonMakeData(requestData);m_RestApi.ExecuteRequest("/api/auth","POST", data);