Usage in a website and mobile application


#1

DreamFactory looks really nice with it’s rich feature set, but i have following scenario and i’m not really sure if DreamFactory is the way to go here:

  • A normal website frontend written in PHP,
  • Mobile App which will be written in React Native

DreamFactory looks like a really awesome solution for the Mobile App.
But i’m not sure how to realize a normal Website which should use the comfort of DreamFactory Resources and Functions (like User authentification, File storage, …).
Sure, i probably could make CURL calls in my PHP code to use the DreamFactory functions, but wouldn’t that be too much overhead?
I couldn’t find any clues if i can directly use the dfe-classes that are on Github like dfe-database, dfe-core, …

Can anybody provide me with some clues?

Regards,
Gianluca


#2

You might want to look at Appery.io for your mobile front-end. They have a drag-and-drop UI and it gives you access to the event-level functions and reduces the amount of code you need to write. They support jquerymobile, ionic, and angularjs and anything cordova pretty much works and they generate the sourcecode for your Android and IOS apps so if you need something pure native, you can use their code as a starting point.

I think the advantage of using dreamfactory is as follows:

  1. You don’t have to write a middle-tier to connect to your database. Just set up your connection string and your entire database now automatically has a middle-tier created for you.
  2. You can re-use the same service layer between your mobile app and your web app.

If you find something that works for web like Appery.io does for mobile, I’d love to hear about it. You can use Appery.io to generate an html version of your site, my problem with that is that they use javascript to access/map all of your services which means that anyone can download your html to reverse-engineer your services. Harder to do on mobile if you connect through SSL.


#3

Thank you crystal. My concerns are not so much with the mobile app side. I think Dreamfactory does a great job here.
My problem is with the web front-end. Since the web front-end should have the same functionality as the mobile app (User can login, Post content, Share content and so on …), i would like to build the front-end side with PHP and a Framework like Zend or YII.
What i dont understand what the best practice would be here to access the functionality that Dreamfactory provides (as far i can see there is no PHP SDK available).


#4

@gzumaglini I think cURL calls are a great place to start. For example the following PHP snippet would log in a user:

<?php $data = array( 'email' => 'user@example.com', 'password' => 'password' ); $data_string = json_encode( $data ); $curl = curl_init(); curl_setopt( $curl, CURLOPT_URL, 'http://yourURL:8080/api/v2/user/session'); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data_string) ) ); curl_setopt( $curl, CURLOPT_POSTFIELDS, $data_string ); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $result = curl_exec( $curl ); curl_close( $curl ); $myData = json_decode( $result ); ?>

With that you can use the session token to make additional calls with the session token retrieved from the initial API call. You can use the token + API key in the CURLOPT_HTTPHEADER section to validate the user session for the calls: Example:

<?php $curl2 = curl_init(); curl_setopt( $curl2, CURLOPT_URL, 'http://youURL:8080/api/v2/db/_table/contact'); curl_setopt( $curl2, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'X-DreamFactory-API-Key: yourAPIkey', 'X-DreamFactory-Session-Token: ' . $myData->session_token ) ); curl_setopt($curl2, CURLOPT_RETURNTRANSFER, true); $result2 = curl_exec( $curl2 ); curl_close( $curl2 ); etc...etc... I hope this helps give you some idea.

#5

Hey gzumaglini, how did you end up connecting to Dreamfactory with React Native? There is no SDK. Only for React…? PLease help!