0

I've asked this question on stackoverflow, but i think this is a more appropriate place for it.

I'm creating an app for iOS, Android and the Web. I created a separate Restful Data Service that is meant to be consumed by all three environments, so I separated the Logic, and all of the apps can consume it at api.mysite.com.

To login, you have to hit the DataService, pass the username and password, and it returns a token, for which should be used in each subsequent request to the DataService. Thats all fine and dandy for iOS and Android, but gets a little tricky when it comes to JavaScript/HTML/PHP environment.

In that environment, PHP hits the server for a few initial objects that it bootstraps the rendered HTML page with. Then, the javascript runs client side and consumes the bootstrapped data. If the JavaScript needs to edit, get more, or delete objects, it has to hit the DataServer.

How should I construct the communication between the WebServer, the DataServer and that Javascript? I assume I'd need to sessions between the WebServer and the Javascript, and Tokens between the WebServer and the DataServer...And I'd need to either bootstrap the Token to the rendered HTML so the Javascript can communicate with the server as well, or have it communicate with proxy scripts on the WebServer, which then communicates to the DataServer as necessary.

Whats the best practice here? Is there one? Whats a good structure to follow?

  • If this is a single page app you can do the same thing you do in the mobile apps. For multiple pages, you can use sessions. – GrandmasterB Jan 22 '15 at 20:27
  • It'a actually a multipage app. How would I use sessions here ? – projectnard Jan 22 '15 at 20:58
  • Just regular sessions via PHP would work. – GrandmasterB Jan 22 '15 at 21:09
  • I'm not cause of what you mean by regular sessions. Should I use a regular session between the client side JavaScript and the webapp's php? If so, how should the JavaScript then contact the dataservice when needed? – projectnard Jan 23 '15 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.