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:
Implementing authentication
Cancel

The Web API Framework in DataFlex

Lesson 4 - Routers

In this quick lesson, we’re diving into routers — a small but powerful piece of your web API puzzle. Ready? Let’s go!

  1. Step 1: Understand What Routers Are
    Routers themselves are just a way to organize your URL paths. By default, they don’t do much alone — just a neat way to group endpoints under one path. But combine routers with things like authentication or authorization, and you unlock powerful features. We’ll get there soon!
  2. Step 2: Create Your Router
    Let’s jump into the code. Going back to our cWebApi object, where you already have your endpoints set up. Now, create a router:
    • oMyRouter is a cWebApiRouter 

      End_Object 

  3. Step 3: Set the Router’s Path
    Next, assign a path to your router. Let’s use the DF Learning Center as our example path:
    • Object oMyRouter is a cWebApiRouter 

           Set psPath to “dflc” 

      End_Object 

    • This means any endpoint inside this router will start with /dflc in the URL. 
  4. Step 4: Move an Endpoint Inside Your Router
    Now, take one of your existing endpoints and move it inside the router. For example, move the inventory endpoint inside myRouter like this:
    • Object oMyRouter is a cWebApiRouter 

           Set psPath to “dflc” 

           Use InventoryEndpoint.pkg 

      End_Object 

  5. Step 5: Compile and Test
    Compile your project and open your browser to check the OpenAPI specification. You should now see your inventory endpoint listed under the /dflc URL path — something like:
    • /dflc/Inventories.
  6. Step 6: What’s Next?
    Right now, the router itself just changes your URL structure — handy for organizing your API, but not yet game-changing. In the next lesson, we’ll add authentication to this router, making it super powerful by controlling access and security.

You’re all set to experiment with routers! Want to keep leveling up? Stay tuned for the authentication lesson next.