Build a RESTful webservice in 3 lines of code

How to make a simple RESTful web service in Uniface.
From my blog: The Uniface Universe

After building both SOAP and RESTful webservices in Uniface my opinion is: use REST when you can, SOAP when you must. This article explains why: REST vs. SOAP ? The Right WebService

Not many people know how easy it is to build RESTful webservices in Uniface. Because you do not need special statements or features there is no information on it in the documentation.

Here are the steps for building a (very) basic RESTful webservice:

  1. Create a new DSP component RESTBLOG
  2. Remove all code from all triggers (especially Set State)
  3. Add a dummy entity
  4. Enter this sample code into the Execute trigger:

    public web
    variables

    string vInput  ; Input parameter from URL
    string vOutput ; Output content to be returned
    endvariables
       ; — 1 — get input parameter
    getitem/id vInput, $webinfo(“INPUT”), “name”

    ; — 2 — create output based on input
    ; you can do anything here
    vOutput = “Hello %%vInput%%%, I am the output”

    ; — 3 — fill the output channel
    $webinfo(“output”) = vOutput

    ; And we are done !
    return(0)

    end

  5. Compile
  6. Test using a URL like http://localhost:8086/uniface/wrd/RESTBLOG?name=Theo
  7. Congratulations, you have just build your first Uniface RESTful web service!

 

NB: We did NOTHING in the Layout Editor!

One thought on “Build a RESTful webservice in 3 lines of code”

  1. This works great, thanks. Has anyone tried to call a RESTful web service, DSP or USP, in Uniface sending an XML file as the input payload?

    We have many nTier Uniface functions that accept XML as the input for data insert/update by a Uniface service component. Now that we have a Uniface web application running, I’ve been asked to figure out how we could bring the XML (or JSON if possible) into our Uniface services via a RESTful web service call and return the data update result via an XML/JSON response. We are currently running Uniface 9.4 and have started a migration to Uniface 9.6.

    Thanks in advance for any advice.

Leave a Reply