Download the PHP package dreamfactory/javascript-sdk without Composer
On this page you can find all versions of the php package dreamfactory/javascript-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dreamfactory/javascript-sdk
More information about dreamfactory/javascript-sdk
Files in dreamfactory/javascript-sdk
Package javascript-sdk
Short Description DreamFactory Services Platform(tm) Javascript SDK
License Apache2.0
Homepage http://dreamfactorysoftware.github.io
Informations about the package javascript-sdk
Address Book for JavaScript
This repo contains a sample address book application for JavaScript that demonstrates how to use the DreamFactory REST API. It includes new user registration, user login, and CRUD for related tables.
Installing DreamFactory on your local machine
To download and install DreamFactory, choose the desired installation package here.
Configuring your DreamFactory instance to run the app
-
Enable CORS for development purposes.
- In the admin console, navigate to the Config tab and click on CORS in the left sidebar.
- Click Add.
- Set Origin, Paths, and Headers to *.
- Set Max Age to 0.
- Allow all HTTP verbs and check the Enabled box.
- Click update when you are done.
- More info on setting up CORS is available here.
-
Create a default role for new users and enable open registration
- In the admin console, click the Roles tab then click Create in the left sidebar.
- Enter a name for the role and check the Active box.
- Go to the Access tab.
- Add a new entry under Service Access (you can make it more restrictive later).
- set Service = All
- set Component = *
- check all HTTP verbs under Access
- set Requester = API
- Click Create Role.
- Click the Services tab, then edit the user service. Go to Config and enable Allow Open Registration.
- Set the Open Reg Role Id to the name of the role you just created.
- Make sure Open Reg Email Service Id is blank, so that new users can register without email confirmation.
- Save changes.
-
Import the package file for the app.
- From the Apps tab in the admin console, click Import and click 'Address Book for JavaScript' in the list of sample apps. The Address Book package contains the application description, source code, schemas, and sample data.
- Leave storage service and folder blank. It will use the default local file service named 'files'.
- Click the Import button. If successful, your app will appear on the Apps tab. You may have to refresh the page to see your new app in the list.
-
Decide if you're going to run the app locally or load it from the instance.
- For running locally you clone the repo to your machine and open index.html in the browser. If running locally you need to set the URL for your instance so the app can make the API calls. Go to your local repo and edit script.js. Set the constant
INSTANCE_URL
to point to your DreamFactory instance such as http://localhost:8080. - For running from the instance you launch the app directly from the Apps tab in the admin console. Leave
INSTANCE_URL
set to empty string.
- For running locally you clone the repo to your machine and open index.html in the browser. If running locally you need to set the URL for your instance so the app can make the API calls. Go to your local repo and edit script.js. Set the constant
-
If running from instance make your app files public.
- Figure out where your app files are stored. If you used the default storage settings to import the app, it'll be the default local file service named 'files'.
- Go to the Files tab in the admin console. Find your file service. Double click and find the folder for your app, e.g.,
AddressBookForJavaScript
. - Go to the
Services
tab in the admin console and click thefiles
service. Click theConfig
tab and add the folder nameAddressBookForJavaScript
as a public path. Now select the relevant container from the Container drop down. If you used the default storage settings to import the app then selectlocal
from the drop down list. Save your changes.
-
Edit your app API key
- If you are running from instance use the file manager to edit
script.js
and setAPP_API_KEY
to the key for your new app. The API key is shown on the app details in the Apps tab of the admin console. - If you are running locally edit
script.js
in your local repo.
- If you are running from instance use the file manager to edit
- Make sure you have a SQL database service named
db
. Most DreamFactory instances have a defaultdb
service for SQLite. You can add one by going to theServices
tab in the admin console and creating a new SQL service. Make sure you set the name todb
.
Running the Address Book app
You can launch the app from the Apps tab in the admin console, or by opening your local index.html
in your browser.
When the app starts up you can register a new user, or log in as an existing user. Currently the app does not support registering and logging in admin users.
Example API calls
The DreamFactory Address Book for JavaScript uses AJAX to make API calls and the file functions.js
contains the most common functions for CRUD operations.
The general form of a DreamFactory REST API call is:
<rest-verb> http[s]://<server-name>/api/v2/[<service-api-name>]/[<resource-path>][?<param-name>=<param-value>]
The JavaScript app AJAX call format is:
Breaking down each parameter:
- dataType Format of the returned data. This depends on the application, but will typically be JSON.
- contentType The format of data sent to the API. This is commonly JSON and char set UTF-8.
- url Holds the value of
http[s]://<server-name>/api/v2/[<service-api-name>]/[<resource-path>]
from the generic call. You can include the query parameters here. However, it is easier and cleaner to pass in the query parameters by using the data parameter than it is to format them into the url. - data The (optional) query parameters.
- method The REST verb.
- headers The header object must include the app specific API key and a session token.
Login and Registration Examples
Login
The user/session
API request will return a session token.
Registration
The API request will return a session token when the (optional) login=true
parameter is appended to the url. So with this parameter appended, the new registered user doesn't have to login to get a session token.
The login and registration examples illustrates how to make API requests to DreamFactory. This Address Book app has functions for common API request types, so in the following examples these functions are used.
Examples of Fetching Records
Fetch All Records in Table
Fetching Specific Fields
Fetching with a Filter Applied
Creating a Record
Deleting Records
Deleting a Single Record by ID
Deleting Multiple Records by ID
Deleting Records Matching Field Conditions
Additional Resources
More detailed information on the DreamFactory REST API is available here.
The live API documentation included in the admin console is a great way to learn how the DreamFactory REST API works.