DayZ
  • 🌶️FoxApo DayZ Mods
  • ⚙️Modding | Repacking
  • MODS
    • 👻CRDTN Creatures
      • Phantom
      • config.cpp
    • 💯CRDTN Core
      • File Logger
        • Logger Player Connected
      • Rest Api
        • Getting started
      • Event Handler
      • Notifications UI
      • Admin Utils
      • NPCs
    • 📺CRDTN Gui
    • 📦CRDTN Krabice
    • 🫂CRDTN Factions
    • ⁉️CRDTN Quests
      • ⁉️Getting started
      • 💻Client Side
      • 🖥️Server Side
        • ⚙️Installation
          • 🛠️Quests.json
            • ⚔️Goal
            • 🎁Reward
          • 🌎Quest Events
            • Teleport quest with quest event (server)
        • ⚙️Quest & Goal Types
          • 📜Turn-In goal
          • 📜Kill goal
          • 📜Trade goal
          • 📜Craft goal
          • 📜Action goal
          • 📜Explore goal
        • ⚙️Rewards
        • ⚙️Quest NPCs
    • 🔥CRDTN Fire Regen
      • Config
    • 🔊CRDTN Sounds
    • 🚪CRDTN Locked Doors
      • Config
      • How To
      • config.cpp
Powered by GitBook
On this page
  1. MODS
  2. CRDTN Core
  3. Rest Api

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);
PreviousRest ApiNextEvent Handler

Last updated 1 year ago

💯