Design a RESTful service

WATCH: Designing your Sample Solution

Your trial of the Linx Application Cloud includes a pre-loaded simple REST Web Service. The solution gives you a head start in learning what’s possible with Linx.


What does the Sample Solution do?

We created 2 different methods to call a REST web service as a sample to illustrate the flexibility of Linx. Of course, we built it all in Linx, so here’s how we did it.

1) HelloREST – This solution check a folder for a new text file. If a text file exists, a new record is written to the database, including the file name and contents. We then created a web service that calls the database table for a record of the name provided in the text file and returns it – displayed in the browser.

The solution has a timer event that executes at 1 minute intervals to check a folder for the existence of any text files.

2) JokeREST – This operation calls an API that returns a random joke. The joke is then displayed in the browser.

View the Sample Documentation


Setting up the Timer Service

We created a Timer service to execute a process that reads a file off a drive, extracts the file name and add it to a database.

  • Configure the Timer service to run at a specific interval which is stored as a Setting value.
  • Adding a FileList function to the process and configure the FileList properties to scan the target location based on a Setting value, then setting up the search pattern using the text editor, finally indicating that the process must loop for each file found.
  • Drag and drop a TextFile Function in the execution path of the FileList function.
  • Configure the File Path property to read from using the expression editor. Everytime the FileList function picks up a file, the process will then read that file.
  • Add a ExecuteSQL function to the process and configure its properties by changing the name, referencing the database connection string stored as a setting.
  • Create the SQL insert statement to insert values retrieved from the above functions by making use of the expression editor. This will insert into the database the File Name of the file picked up by the file list and the file contents of the TextFileRead function.
  • Lastly, add a File Move function and configuring the properties to move the file from the source location (made up of expression modifications), to the target location stored in the Settings.database the File Name of the file picked up by the FileList function and the file contents of the TextFileRead function.
  • Lastly, add a FileMove function and configure the properties to move the file from the source location to the target location.

HelloREST

Creating a REST web service that takes in a Name as an input parameter, searches the Database for a Greeting that corresponds to the input parameter, if found, it returns the greeting associated with the name. If no name is found it returns a generic instruction message.

  • Add a RESTful web service function by dragging it from the plugin panel onto the project. Configure the REST web service API definition by pasting in the swagger definition into the REST web service properties using the text editor. This creates the process structure of our web service, with the first method “Hello” visible.
  • Add a ExecuteSQL function to the “Hello” method/process. Its properties are configured to connect to the Database and uses a select statement to retrieve greetings from the Database that matches the input name.
  • Lastly, we added a decision function. The properties for this are configured to make a decision based on the result returned from the Database read. Depending on the result of the decision, the output parameter of the REST web service is set appropriately.

AnyAPI  / JokeREST

We created a REST web service function , that when called, calls an external REST webs service that returns a joke, this joke is then returned as an output.

  • We started by extending the existing REST  web service swagger definition to add another method called “Joke”.
  • We added a CallRESTWebService function by dragging it from the plugin panel onto the “Joke” method process. The properties of the CallRESTWebserive function are then configured to point at a web service that returns Chuck Norris Jokes.
  • In order for the output to be returned, we created a CustomType that holds a value.  The output property of the RESTWebserviceCall is set as the CustomType just created.
  • A string type is then added and set to the output of the RESTWebserviceCall along with an additional message.
  • Finally, a SetValue function is added that sets the output of the Joke Rest web service.

Try it: Download the Linx Application Designer to try this yourself.

Need help?Let our experienced development team build a solution for you.



Scroll to top