---
title: "View source for Scripting Resources - DreamFactory Wiki"
source: "http://wiki.dreamfactory.com/index.php?action=edit&title=Scripting_Resources"
canonical_url: "http://wiki.dreamfactory.com/index.php?action=edit&title=Scripting_Resources"
converted_at: "2026-10-23T22:52:49.801Z"
format: "markdown"
converted_by: "html-to-md-ai"
---
[]()
	
	
	
	# View source for Scripting Resources

	
		
		← [Scripting Resources](/Scripting_Resources)
		
		
		
		[Jump to navigation](#mw-head)
		[Jump to search](#searchInput)
		You do not have permission to edit this page, for the following reason:

The action you have requested is limited to users in the group: [Users](/index.php?title=DreamFactory_Wiki:Users&action=edit&redlink=1).---

You can view and copy the source of this page.

{{#seo:
|title=Scripting Resources - DreamFactory Documentation
|title_mode=replace
|canonical=https://wiki.dreamfactory.com/Scripting_Resources
|og:title=Scripting Resources
|og:type=article
|og:site_name=DreamFactory Documentation
}}
&lt;span id="scripting-resources">&lt;/span>
= Scripting resources =

This page provides a comprehensive overview of the resources available for scripting in DreamFactory, including links to sample scripts and documentation references for event scripting and scripted services.

&lt;span id="overview">&lt;/span>
== Overview ==

DreamFactory's scripting capabilities allow you to extend the functionality of your APIs by executing custom scripts in response to events or as standalone services. These scripts can be written in various supported languages and can interact with the DreamFactory platform to perform complex operations.

&lt;span id="supported-scripting-languages">&lt;/span>
== Supported Scripting Languages ==

DreamFactory offers an extraordinarily powerful solution for creating APIs and adding business logic to existing APIs using a variety of popular scripting languages including PHP, Python, Node.js, and JavaScript. In this section we walk through several examples to spur your imagination regarding the many ways you can take advantage of this great feature.

&lt;span id="supported-scripting-languages-1">&lt;/span>
== Supported scripting languages ==

DreamFactory has several scripting languages available for customized scripting of endpoints and services. To get a list of the currently supported and configured scripts on a particular instance, use the API endpoint:

DreamFactory supports several scripting languages:

* '''Node.js''': Server-side JavaScript handler using the Node.js engine.
* '''PHP''': Script handler using native PHP.
* '''Python''': Script handler using native Python.
* '''Python3''': Script handler using native Python3.

&lt;span id="programmatic-resources-available-to-scripts">&lt;/span>
== Programmatic Resources Available to Scripts ==

When a script is executed, DreamFactory provides two primary resources:

* '''Event Resource''': Contains data about the event triggering the script.
* '''Platform Resource''': Allows access to configuration, system states, and internal API calls.

&lt;span id="event-resource">&lt;/span>
=== Event Resource ===

The following languages are typically supported on DreamFactory installations

The event resource includes properties such as &lt;code>request&lt;/code>, &lt;code>response&lt;/code>, and &lt;code>resource&lt;/code>, which represent the inbound REST API call, the response, and any additional resource names, respectively.

{| class="wikitable"
|-
! '''Property'''
! '''Type'''
! '''Description'''
|-
| '''request'''
| resource
| Represents the inbound REST API call, i.e. the HTTP request
|-
| '''response'''
| resource
| Represents the response to an inbound REST API call, i.e the HTTP response
|-
| '''resource'''
| string
| Any additional resource names typically represented as a replaceable part of the path, i.e. &lt;code>table name&lt;/code> on a &lt;code>db/_table/{table_name}&lt;/code> call
|}

&lt;span id="event-request">&lt;/span>
==== Event Request ====

The '''request''' resource contains all the components of the original HTTP request. This resource is always available, and is writable during pre-process event scripting.

{| class="wikitable"
|-
! '''Property'''
! '''Type'''
! '''Description'''
|-
| '''api_version'''
| string
| The API version used for the request (i.e. 2.0).
|-
| '''method'''
| string
| The HTTP method of the request (i.e. GET, POST, PUT).
|-
| '''parameters'''
| resource
| An object/array of query string parameters received with the request, indexed by the parameter name.
|-
| '''headers'''
| resource
| An object/array of HTTP headers from the request, indexed by the lowercase header name. Including content-length, content-type, user-agent, authorization, and host.
|-
| '''content'''
| string
| The body of the request in raw string format.
|-
| '''content_type'''
| string
| The format type (i.e. "application/json") of the raw content of the request.
|-
| '''payload'''
| resource
| The body (POST body) of the request, i.e. the content, converted to an internally usable object/array if possible.
|-
| '''uri'''
| string
| Resource path, i.e. /api/v2/php.
|-
| '''service'''
| string
| The type of service, i.e. php, nodejs, python.
|}

&lt;span id="where-to-use-dreamfactory-scripting">&lt;/span>
== Where to use DreamFactory scripting ==

Scripts can be used in two places in DreamFactory, '''''Event Scripts''''' and '''''Scripted APIs'''''. '''''Event Scripts''''' is tied to and triggered by API calls, internal events, or other scrips. The other way scripts are used is through customize-able script APIs. There is a scripting API type for each supporting scripting language listed above.

&lt;span id="programatic-resources-available-to-a-script">&lt;/span>
== Programatic resources available to a script ==

When a script is executed, DreamFactory passes the script(s) two primary resources to allow the script to access many parts of the system, including the state, configuration and even the ability to call other internal or external APIs. They are the '''event''' and '''platform''' resources described below.

&lt;span id="event-response">&lt;/span>
==== Event Response ====

The '''response''' resource contains the data being sent back to the client from the request.

{| class="wikitable"
|-
! '''Property'''
! '''Type'''
! '''Description'''
|-
| '''status_code'''
| integer
| The HTTP status code of the response (i.e. 200, 404, 500, etc).
|-
| '''headers'''
| resource
| An object/array of HTTP headers for the response back to the client.
|-
| '''content'''
| mixed
| The body of the request as an object if the content_type is not set, or in raw string format.
|-
| '''content_type'''
| string
| The content type (i.e. json) of the raw content of the request.
|}

&lt;span id="platform-resource">&lt;/span>
=== Platform Resource ===

&lt;span id="event-resource-1">&lt;/span>
=== Event resource ===

The event resource contains the structured data about the event triggered (Event Scripts) or from the API service call (Script APIs). As seen below, this includes things like the request and response information available to this "event".

In order for a script to modify the event resource, the script must be configured to allow modification to events. This is done in the script editing screen by checking the '''Allow script to modify request payload''' checkbox.
The platform resource provides access to the instance's REST API, configuration settings, and session information. It includes methods for making internal API calls using REST verbs like &lt;code>get&lt;/code>, &lt;code>post&lt;/code>, &lt;code>put&lt;/code>, &lt;code>patch&lt;/code>, and &lt;code>delete&lt;/code>.

{| class="wikitable"
|-
! '''Property'''
! '''Type'''
! '''Description'''
|-
| '''api'''
| resource
| An array/object that allows access to the instance's REST API
|-
| '''config'''
| resource
| An array/object consisting of the current configuration of the instance
|-
| '''session'''
| resource
| An array/object consisting of the current session information
|}

&lt;span id="platform-api">&lt;/span>
==== Platform API ====

&lt;span id="event-request-1">&lt;/span>
==== Event request ====

The '''api''' resource contains methods for instance API access. This object contains a method for each type of REST verb.

{| class="wikitable"
|-
! '''Function'''
! '''Description'''
|-
| '''get'''
| GET a resource
|-
| '''post'''
| POST a resource
|-
| '''put'''
| PUT a resource
|-
| '''patch'''
| PATCH a resource
|-
| '''delete'''
| DELETE a resource
|}

They all accept the same arguments:

&lt;syntaxhighlight lang="text">
method( &amp;quot;service[/resource_path]&amp;quot;[, payload[, options]] );
&lt;/syntaxhighlight>
&lt;span id="helpful-links-and-sample-scripts">&lt;/span>
== Helpful Links and Sample Scripts ==

Explore a variety of scripting examples and resources to help you get started with DreamFactory scripting:

* '''[https://github.com/dreamfactorysoftware/example-scripts df-scriptingexamples Repository]''': A collection of sample scripts demonstrating how to leverage DreamFactory's scripting capabilities.
* '''[[Event_Scripts|Event Scripting Documentation]]''': Learn how to create and manage event scripts in DreamFactory.
* '''[[Scripted_Services_And_Endpoints|Scripted Services Documentation]]''': Discover how to create standalone scripted services and endpoints.

&lt;span id="best-practices">&lt;/span>
== Best Practices ==

# '''Modularize your code''': Break down complex logic into smaller, reusable functions.
# '''Handle errors gracefully''': Implement error handling to manage exceptions and provide meaningful error messages.
# '''Optimize performance''': Minimize script execution time to ensure efficient API responses.
# '''Secure your scripts''': Validate inputs and sanitize outputs to prevent security vulnerabilities.

&lt;span id="troubleshooting-tips">&lt;/span>
== Troubleshooting Tips ==

# '''Check script syntax''': Ensure your script has correct syntax for the chosen language.
# '''Enable error logging''': Use DreamFactory's logging features to capture script errors.
# '''Test incrementally''': Start with simple scripts and gradually add complexity.
# '''Use platform.api for debugging''': Make API calls within your script to test functionality.
# '''Monitor performance''': Be mindful of script execution time, especially for complex scripts.

By utilizing these resources and best practices, you can effectively extend DreamFactory's capabilities and create powerful, customized API solutions.

[[Category:API]]
[[Category:Scripting]]
[[Category:Resources]]

[[Category:API]]
[[Category:Scripting]]
Return to [Scripting Resources](/Scripting_Resources).

Retrieved from "[https://wiki.dreamfactory.com/Scripting_Resources](https://wiki.dreamfactory.com/Scripting_Resources)"