4D Blog

Home Product ORDA – Improve your API with function scope

ORDA – Improve your API with function scope

October 22, 2020

Product

4D v18 R4 and ORDA made it possible for you to create high-level class functions above the data model. This allows you to write business-oriented code to hide complexity, reduce errors, and speed up the development process.

With 4D v18 R5, we’re bringing even more features to help you optimize and organize your code. For example, you might need to run a function locally on the client to improve performance when working in client/server mode. It’s now possible! Or if you expose your database as a REST server, you might want some functions to be available on the server-side but hidden for your REST clients. This is also possible!

HDI: Functions keywords in ORDA data model classes

 

Two new keywords for functions in ORDA data model classes are available:

working in C/S with the LOCAL keyword

Functions are executed on the server by default in C/S, but you can now choose to execute some of them on the client. This can greatly improve performance.

Example

In this example, we have a Students dataclass. Let’s write a function that returns the student’s ages.

blank

 

Here is our age() function in the cs.StudentsEntity entity class.

Class extends Entity

// This is an estimate of the age
local Function age() : Variant
If (This.birthDate#!00-00-00!)
 $0:=Year of(Current date)-Year of(This.birthDate)
Else
 $0:=Null
End if

And this is a list box displaying all the students with the age column mapped with the expression This.age():

blank

 

Thanks to the local keyword, the age() function is executed locally on the client with the birthdate loaded while displaying the list box. This is important to be in tune with the 4D v17 R5 ORDA requests optimization.

Without the local keyword, the age() function would trigger a request to the server for each line!

exposed keyword

As promised with 4D v18 R4, we’ve enhanced exposing functions for the REST server. Now with 4D v18 R5, you can choose which functions to publish (or not).

You can use the exposed keyword to have a function published as an API for REST clients.

In the example below, the registerNewStudent() function in the cs.Students dataclass class  is callable from a REST client while computeStudentId() is not.

Class extends DataClass

exposed Function registerNewStudent($student : Object) : Object
var $entity : cs.StudentsEntity
var $status : Object

$entity:=ds.Students.new()
$entity.fromObject($student)
$entity.studentId:=This.computeStudentId()
$status:=$entity.save()

If ($status.success)
  $0:=$entity
Else
  $0:=$status
End if

// This function not callable from a REST client
Function computeStudentId() : Integer
//compute a new student Id
Use (Storage.
infos)
  Storage.
infos.studentId:=Storage.infos.studentId+1
$0:=Storage.
infos.studentId
End use

Here is the calling code on the REST client:

var $connect;$ds;$student;$result : Object
var $studentId : Integer

$connect:= New object("hostname";"127.0.0.1:8044")
$ds:=Open datastore($connect;"demo")

$student:=New object("firstname"; "Mary"; "lastname"; "Smith")
// Execution is OK, no error is raised
$result:=$ds.Students.registerNewStudent($student)

//An error is raised
$studentId:=$ds.Students.computeStudentId()

Note: In 4D v18 R4, all functions are exposed on the REST server. In 4D v18 R5, functions are NOT exposed by default. Don’t forget to mark the functions you want to expose.

Check out the documentation and the HDI above to learn more about the new features!

 

Discuss

Tags API, Client/Server, Data model, ORDA, REST server, v18 R5, v19

Latest related posts

  • December 3, 2025

    Give AI to a 30 years old 4D application

  • November 28, 2025

    ORDA – Handle an event-driven logic during database operations

  • November 27, 2025

    ORDA – Permissions – Restrict / allow web access to the resources in one click

Avatar
Marie-Sophie Landrieu-Yvert
- Product Owner - Marie-Sophie Landrieu-Yvert joined the 4D Product team as a Product Owner in 2017. In this role, she is responsible for writing user stories and translating them into functional specifications. She also ensures that the delivered feature implementation meets the customer's needs. Marie-Sophie graduated from the engineering school ESIGELEC and began her career as an engineer at IBM in 1995. She took part in various projects (maintenance and development projects) and worked as a COBOL developer. She then moved on to work as a UML designer and Java developer. More recently, her main responsibilities included analyzing and writing functional requirements, and coordinating business and development teams.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy