Getting started

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

class ExampleApi
{
    // Suggestion is to cache the api reference (do not create new instance for each call) 
    protected ref CRDTN_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

class ExampleApi
{
    // Suggestion is to cache the api reference (do not create new instance for each call) 
    protected ref CRDTN_RestApiWrapper m_RestApi;
    
    void ExampleApi()
    {
        // https://my-backend-server
        string url = ""; // Use some endpoint you need to call request on 
        m_RestApi = new CRDTN_RestApiWrapper(url);
    }
};

Using GET method

// Instantiate the api instance for the URL 
autoptr CRDTN_RestApiWrapper m_RestApi = new CRDTN_RestApiWrapper("https://my-backend-server");

// Using callback events
m_RestApi.ExecuteRequest("/endpoint", "GET", "");

Using POST method

RestApiResponse<string> requestData = new RestApiResponse<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);

Last updated