Zingy Docs
Visit our websiteTry a DemoPricingContact
  • Introduction
  • 🎛️Dashboard
    • Overview
    • Apps
    • Account Profile
    • Billing - View Invoices
    • Billing - Payment Methods
    • Billing - Subscription
  • 💻App Editor
    • App Components
    • App Editor Tour
    • App Settings
    • App Users
    • App User Groups
    • Publishing your App
    • Pages and Forms
      • Create a Page
      • Create a Structured Page
      • What is a Structured Page ?
      • Create a Form
      • Page Editor
      • Working with Forms
    • Page Editor
      • Page Editor Tour
      • Adding Page Content
      • Adding Content to Structured Pages
      • Working with Page Elements
      • Page Element Settings
      • Responsive Design
      • Padding and Margin
      • Editing Text
      • Using AI Wiz in the Page Editor
      • Built-in elements
        • Link
        • Image
        • Spacer
        • Flexible Area
        • Layout Container
        • Layout Row
        • Layout Column
        • 1 Column
        • 2 Columns
        • 3 Columns
        • Add Column
        • Table
        • Table Row
        • Table Column Cell
        • Table Heading Cell
        • Table (3 cols)
        • Table (4 cols)
        • Input
        • Checkbox
        • Toggle Switch
        • Dropdown
        • Multi-line
        • Label
        • Button
        • Button Group
        • Input Group
        • Button Toolbar
        • Menubar Holder
        • Menubar Collapsible
        • Menubar
        • Menubar Item
        • Menubar Item Link
        • Menubar Style1
        • Menubar Style2
        • Menu Item
        • Popup Menu
        • Popup Menu Item
        • Menubar Popup Menu
        • Popup Menu Style1
        • Popup Menu Style2
        • Popup Menu Separator
        • Card
        • Card Group
        • Card Style1
        • Card Style2
        • Card Style3
        • Alert
        • Badged Text
        • Collapsible Area
        • Data Table
        • Stripe Payment
        • Form
        • Menubar Login Info
        • Data Design
      • Working with Forms
      • Using Forms
      • Page Preview
    • Page Settings
    • Page Flow
      • Block Anatomy
      • Toolbox Blocks
        • Set Content
        • Get Content
        • Badged Text
        • Alert Text
        • Status Animation
        • Set Style
        • Set CSS
        • Set Input Value
        • Get Input Value
        • Set Toggle Switch State
        • Get Toggle Switch State
        • Set Input Feedback
        • Enable/Disable Element
        • Set Element Attribute
        • Get Element Attribute
        • Get Element by Name
        • Element
        • URL Parameter Value
        • Navigate Page
        • Timer
        • Timer Repeat
        • Show Popup Form
        • Show Information Popup
        • Show Confirmation Popup
        • Popup Form Data
        • Collapsible Area Action
        • Mouse/Keyboard Action
        • Event Action
        • Action/Event Info
        • Show Menu
        • Menu Text
        • Menu Index
        • Write Log Message
        • Log Category
        • Data Table Action Menu Customize
        • Data Table Attach Form
        • Data Table Add Action
        • Data Table Load Next Page
        • Data Table Load Prev Page
        • Data Table Refresh
        • Data Table Custom Query
        • Data Table : Table Name
        • Data Table : Data
        • Content from Data Design
        • Set Content in Data Design
        • Get Content in Data Design
        • Get Element Attribute in Data Design
        • Set Element Attribute in Data Design
        • Set Style in Data Design
        • Set CSS in Data Design
        • Set Input Value in Data Design
        • Get Input Value in Data Design
        • Get Toggle Switch State in Data Design
        • Set Toggle Switch State in Data Design
        • Set Input Feedback in Data Design
        • Enable/Disable Element in Data Design
        • Initialize Toggle Switch in Data Design
        • Event Action in Data Design
        • Collapsible Area Action in Data Design
        • Data Record Count
        • Data Record at Index
        • Data Record Loop
        • Data Record Info
        • Data Record Loop Index
        • Data Record ID
        • Data Table Name
        • Data Query Name
        • Data Read
        • Data Read Next
        • Data Read Previous
        • Data Lookup
        • Data Lookup with ID
        • Data Status
        • Data Add Record
        • Data Update Record with ID
        • Data Delete Record with ID
        • Data Input Popup
        • Lock/Unlock Form
        • Save Form with Data
        • Reset Form
        • Set Form Event Status
        • Set Form Event Status Message
        • Form Submit Complete
        • Set Field Input Value
        • Get Field Input Value
        • Form Data
        • Form in Edit Mode
        • Form Events
        • Execute Connection Command
        • Execute API Call
        • Connection Data
        • Connection Error
        • API Call Connection
        • Connection
        • Connection Command
        • Cloud Flow Invoke Hook
        • Cloud Flow : URL of Web Hook
        • HTTP Post
        • HTTP Get
        • HTTP Data
        • HTTP Error
        • Date
        • Custom Code
        • Date from Text
        • Get Object Property
      • Coding in Page Flow
      • Zingy API For Page Flow
      • References
        • Value Types
        • Popup Customization
        • Prerequisite for Dynamic Content block examples
        • Prerequisite for Data examples
    • Dynamic Content
    • Data
      • Database Tables
      • Database Queries
      • Data Tool
    • Cloud Flow
      • Cloud Flow Editor
      • Block Anatomy
      • Toolbox Blocks
        • Data Update Records
        • Data Delete Records
      • Coding in Cloud Flow
      • SDK/Library Integration
    • Media
    • Connections
      • Services
        • Stripe
        • Sendgrid
        • Twilio
        • API Call
        • API Key
Powered by GitBook
On this page
  • Node.js Libraries/SDKs
  • Cloud Flow Variables and Functions
  • Web Hook Response Streaming
  • Piped (Pass-through)
  • Chunked
  1. App Editor
  2. Cloud Flow

Coding in Cloud Flow

PreviousData Delete RecordsNextSDK/Library Integration

Last updated 1 year ago

For Cloud Flow, the Custom Code block is functional in Business or higher edition apps. This block can be tested in the Standard edition.

In Cloud Flow, the block allows you to add based code for advanced custom functionality.

Node.js Libraries/SDKs

Your Zingy app's server-side backend includes a curated list of Node.js SDKs and Libraries that can be used within your app's Cloud Flow Web Hooks and Background Tasks using the block.

For more information about the list of integrated libraries and sdks please see .

Cloud Flow Variables and Functions

The variables and functions that are added to the Cloud Flow (using blocks) can also be referenced by the code within the block.

Web Hook Response Streaming

support advanced options for sending response to the requesting client as detailed below:

Piped (Pass-through)

When using the Piped (Pass-through) response streaming option, the response data needs to be provided as a to the znResponsePipe function, the prototype for which is shown below:

znResponsePipe(
    readable,     /* stream.Readable */
    contentType,   /* string */
    noAutoExit,    /* boolean */
    endCbFn        /* function */
)
Parameter
Type
Description

readable

The stream to read from and pipe into the response

contentType

string

noAutoExit

boolean

By default, the znResponsePipe function will auto exit the Web Hook once the stream is fully read and piped. This optional parameter allows you to disable this behavior and receive a callback notification at the function specified in the endCbFn parameter.

endCbFn

function

When noAutoExit is set to true, this function gets called when the stream has been read or upon error. A string parameter is passed to indicate the status.

Example

let axios = require('axios');
// URL of the large CSV file
let url = 'https://media.githubusercontent.com/media/datablist/sample-csv-files/main/files/customers/customers-100.csv';
axios({
    method: 'get',
    url: url,
    responseType: 'stream'
}).then(function(httpResp) {
  // Call znResponsePipe with the 
  // readable stream (httpResp.data)
  znResponsePipe(httpResp.data, 'text/csv');  
});

The above example conserves your Zingy app's server-side memory by directly streaming the large CSV file, instead of reading it fully and then transferring it as part of the Web Hook's response.

Chunked

The following functions facilitate this implementation:

znResponseChunkStart(
    contentType /* string */
)
znResponseChunkAdd(
    data /* string/binary/etc */
)

The znResponseChunkAdd (above), is used to send the next chunk of data to the client. The data parameter specifies the chunk to be sent.

znResponseChunkEnd(
    noAutoExit,    /* boolean */
    endCbFn        /* function */
)

The znResponseChunkEnd function, shown above, is used to signal that all chunks have been sent to the client. By default, this function will auto exit the Web Hook. The noAuthExit parameter when set to true, prevents this and calls the function specified by the endCbFn parameter.

Example

Upon receiving the end event, the znResponseChunkEnd function is called to close the response and exit the Web Hook.

let csv = require('csv-parser');
let axios = require('axios');
// URL of the large CSV file
let url = 'https://media.githubusercontent.com/media/datablist/sample-csv-files/main/files/customers/customers-100.csv';
axios({
    method: 'get',
    url: url,
    responseType: 'stream'
}).then(function(httpResp) {
    // call znResponseChunkStart to initiate the response
    znResponseChunkStart('text/plain');
    // Pipe the httpResp.data Readable stream into 
    // the Writeable stream provided by the csv-parser
    httpResp.data.pipe(csv())
    .on('data', (obj) => {
        // convert to JSON and send chunk
        // using znResponseChunkAdd
        znResponseChunkAdd(JSON.stringify(obj)); 
    })
    .on('end', () => { 
        // call znResponseChunkEnd to signal end  
        znResponseChunkEnd(false, null);    
    });    
});

The value for the HTTP in the response.

The example below shows a large CSV file being retrieved from an external source using the library. Since a responseType of stream was specified for , it provides a at httpResp.data , that is passed to the znResponsePipe function. The contentType parameter is set to text/csv.

When using the Chunked response streaming option, the response data is sent in batches (or chunks) to the requesting client. It sets the HTTP header to chunked in the response.

The znResponseChunkStart function, shown above, is used to initiate the response to the client. The contentType parameter specifies the value for the HTTP in the response.

The example below shows the same CSV file (as the Piped example above) being retrieved using the library. Since a responseType of stream was specified for , it provides a at httpResp.data , that is piped into the library.

The library, parses the stream and produces an object for each line parsed. We are notified about this via the data event. In the handler for the data event, we convert the object to a JSON string and send as a chunk using the znResponseChunkAddfunction.

💻
Transfer-Encoding
Content-Type header
stream.Readable
Content-Type header
Custom Code
Node.js
Javascript
Custom Code
SDK/Library Integration
Custom Code
Readable stream
Readable stream
Readable stream
Cloud Flow Web Hooks
axios
axios
axios
axios
csv-parser
csv-parser