With Netuno you can create Web Services and build any kind of complex APIs REST.
Services (Web Services) are used to perform online data integration, where one web system can exchange information with another.
It also provide data to the frontend (web pages) asynchronously, allowing the frontend to load the visual part of the web page faster and then get the dynamic information through integration with services (Web Services).
As will not wait for the whole page to load instead the server will quickly send the structure of the page that will be presented and processed dynamic data gradually, delivering the best User Experience.
To create a service on Netuno you will need a code editor.
Is recommended Visual Studio Code as is a freeware source-code editor, fast, quite simple and intuitive.
However, if you choose any other code editor it will work in a similar way.
How to Open Demo Application
In Visual Studio Code by clicking on the left on the first file where you have the option Open Folder.
Browse the file system to the folder where you have Netuno installed.
Inside the Netuno root folder find the folder:
And when then inside the folder demo click on Open.
Note that the folder and file structure of the application demo has been loaded on the left-hand side.
Creating a Service
The services are processed by the server, so to create a service you must expand the folders and go to the folder:
Now just right-click on the
📂 services folder and choose the New File option.
The name of the new file should be
All you need to do now is to Code our service, which will be as below:
/** *** Formats the past object in JSON and performs its output. */ _out.json( /** *** Gets a list with data objects resulting from the *** query executed in the database. */ _db.query( "SELECT DISTINCT " + " task.name, " + " SUM(DATEDIFF(HOUR, record.inicio, record.fim)) AS total " + "FROM task INNER JOIN record " + " ON task.id = record.task_id " + "WHERE task.active = true " + " AND record.active = true " + "GROUP BY task.name " + "ORDER BY total ASC" ) );
_out.json performs the output (data output) for the browser type
ContentType: application/json and formats the past object to be structured as an object JSON.
_db.query receives a string with a database query and performs its execution by transforming the obtained data into a list of objects of type key/value, i.e. column/data.
Run the Service
To run the service just open in the browser the address of the service that was created which will be: