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:
Creating an endpoint
Cancel

The Web API Framework in DataFlex

Lesson 1 - Setting up the basics

Ready to build your first REST API? In this lesson, we’ll get the basics up and running with just a web API object and an iterator. Let’s dive in!

  1. Step 1: Open Your Web Order Workspace
    Start with the Web Order workspace that comes with your DataFlex installation. If you haven’t done this yet, open it up now.
  2. Step 2: Add the Library
    • Make sure you’ve added the necessary library to your workspace. If you already did this, great — you should see it listed there.
  3. Step 3: Create a New Web Object
    • Go to File > New Web Object
    • Select Web HTTP Handler
    • Give it a name like My REST API
    • Click OK
  4. Step 4: Clean Up the Default Content
    You’ll see some default code inside your new web object. You don’t need any of it, so just delete everything inside.
  5. Step 5: Import cWebAPI class
    Now import the libraries cWebApi class and change the class of the object to: Object oMyRestApi is a cWebApi 
  6. Step 6: Add a cJSONIterator
    • To handle incoming requests and send JSON responses, you need to add an iterator: 

      Send AddIterator (RefClass(cJSONIterator)) “application/json” 

    • This tells your REST API to use the cJSONIterator when a request comes in, so your REST API can process JSON data seamlessly. 

  7. Step 7: You’re Done!
    With these steps, you now have a basic REST API that can receive and respond to requests in JSON format. Easy, right?

In the next lesson, we’ll take it further by creating actual endpoints so you can start building real functionality.