To continue with this content, please log in with your Data Access ID or create a new account.
Cancel Data Access ID
You may not be authorized to see this content. Please contact Data Access Europe for more information.
Cancel Data Access Europe
You are not authorized to see this content.
Cancel Data Access Europe
Next lesson:
Swagger UI
Cancel
  • The Web API Framework in DataFlex

Lesson 2 - Creating an endpoint

  1. Step 1: Create a New DataFlex Source File for Your Endpoint
    • Open your empty web API project.
    • Go to File > New > Other.
    • Choose DataFlex Source File.
    • Name it InventoryEndpoints (or whatever fits your data).
  2. Step 2: Import the cRestDataset class and create a object of this class
    • Inside your new file, import the cRestDataset class. 
    • Define a new object: 
      • Object oInventoryEndpoint is a cRestDataset 
             Set psPath to “Inventories” 
        End_Object 
  3. Step 3: Add Your Data Dictionaries Using the DDO Explorer
    • Open the DDO Explorer at the bottom of the Studio.
    • Click Add DDO and select the Inventory Data Dictionary.
    • Drag and drop the relevant fields you want to expose on the endpoint — for example:
      • Item ID
      • Description
      • Unit Price
      • On Hand
    • These will automatically generate the corresponding C rest fields in your endpoint.
  4. Step 4: Compile and Test Your Endpoint
    • Compile your code.
    • Open Postman (or your favorite API testing tool).
    • Send a GET request to /api/inventories.
    • You should see all records from the inventory table returned!
  5. Step 5: Add Related Data From Another Table (Vendor Info)
    • Imagine you want to include vendor information related to the inventory.
    • Use the cRestEntity class to add this relation. 
    • Define a new vendor entity inside your endpoint:
      • Object oVendorEntity is a cRestEntity

             Set Server to oVendor_DD 

        End_Object 

    • Add the vendor data dictionary via the DDO Explorer.
    • Drag in fields like Vendor ID, Name, Contact Info, etc.
  6. Step 6: Compile and Verify Vendor Data Inclusion
    • Compile your endpoint again.
    • Send the GET request to /Api/Inventories in Postman. (het is case sensitive) 
    • Now, the response will include vendor information alongside each inventory item.
  7. Step 7: Create a Vendor Endpoint Showing Related Inventories
    • Repeat Step 1 to create a new file called VendorEndpoint. 
    • Import the cRestDataset class. 
    • Set up your vendor endpoint: 
      • Object oVendorEndpoint is a cRestDataset 
             Set psPath to “Vendors” 
        End_Object 
    • First include the vendor data dictionary, next import the inventory data dictionary. 
    • Drag the relevant fields from the vendor data dictionary onto the editor. 
      • Use the cRestChildCollection class to add inventories as a related collection under vendors 
        Object oInventoryChildCollection is a cRestChildCollection 
             Set Server to oInventory_DD 
        End_Object 
    • Drag the relevant fields from the inventory data dictionary into this oInventoryChildCollection object. 
  8. Step 8: Compile and Test the Vendor Endpoint
    • Compile your code.
    • In Postman, send a GET request to /Api/Vendors. 
    • You’ll get vendor records with an array of related inventories included.

In the next lesson, we’ll explore the Tracker UI — stay tuned!