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!
- 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. - 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.
- 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
- 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. - Step 5: Import cWebAPI class
Now import the libraries cWebApi class and change the class of the object to: Object oMyRestApi is a cWebApi - 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.
- 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.