Mobile App - Communicating with an external server - php

I'm building a mobile project that needs to be in constant communication with a server and i need some information . I know how to build local apps but this is the first time that i'm building an app that requires external call to a server / authentication service .
I'm asking for guidance how to proceed and which services/servers to use.
What type of server/database do i need ?
I'm guessing i will be requiring an API service but no idea how to choose/make one.
I want to use azure services/database but i also don't want to be dependent on it. I want to have my own url that i send request to and interact with a server/db that i can later move to another host fairly easily.
I develop websites mostly and i'm familiar with php/laravel + Mysql but i think in this case it will be overkill to create a laravel app simply for the server backend .
The app will be mobile only so i don't expect to have a webpage for it . simply an external server/database where the data will be saved.
First i need an authentication service - where each user will register on the phone which will then be saved in my external server/database . Then when they need to login - they will input the login details on the phone , which will query the esternal server/database and if validated - get their details from the server.

First, you need to decide which kind of server communication you'll need. it's in real time and constant? then you'll need a websocket. It's in bursts when you need to send or get data? then you'll need some kind of webservice (REST, RPC, SOAP). Then you have to evaluate the user load you'll have. And finally, the human resources you'll have.
Based on your question, I think a REST webservice will be more than enough. You may:
-Create a REST service for every group of related resources. Example: the /user URL should handle the signup, login, logout and user update operations.
-Create a method for each one of those operations and handle them. Then, call the method from the REST service class.
-Depending on the amount of users and the technology you're using, create a server to handle the requests, or upload your REST project to a server (tomcat, for example).
-Create an app and consume the REST services from there.
There are tons of tech you can choose for these things. PHP allows creating REST services, I think. Java is a very good choice too, since you can use the same code in both server and android apps. Node.Js is pretty popular, too, since you don't need servers and uses NIO (althought java can do both things using jetty and also has multithreading); golang and scala both have superb performance (golang is a lot more easier to learn, though, and it has no need to use external webservers).
Hope this helps.

For mobile applications the best will be REST (representational state transfer),becouse is lightweight and flex to use in other technology. I had project which include REST and mobile app and web app and it working very well.

In this scenario, we usually will build a REST API service for client end. As you are familiar with Laravel, you can refer to http://www.programmableweb.com/news/how-to-build-restful-apis-using-php-and-laravel/how-to/2014/08/13#apiu for how to build a REST API service with Laravel. Also you can leverage other light 3rd part PHP frameworks to build REST API service.
You can create and develop the application on local and then deploy to Azure Web Apps. Please refer to https://azure.microsoft.com/en-us/documentation/articles/app-service-web-php-get-started/ for more info.
And there several vendors provide MySQL services on Azure. ClearDB is a BaaS on Azure for MySQL. You also can use the VM to host your MySQL Service. E.G. MySQL by Bitnami and MySQL by Docker.

Related

How can I connect to my MySQL database backend through Android without exposing it to the public?

I've made an app for Android that uses the Retrofit HTTP API to call PHP scripts which query a database.
App -> Retrofit Call -> PHP -> Database
The PHP and the database are both hosted on the same Amazon EC2 instance.
I would like my app to be deployable to many users, but I don't know how to keep my backend private.
In order for the app to interact with the database, it must use the PHP and since users' IP addresses will vary, I have to keep that PHP code's host's IP address public so that all users can submit/download data.
The problem is that this leaves my backend open to anyone who wants to sniff out the IP address. How can I get around this issue? Is PHP/MySQL a bad choice for Android, or have I simply chosen the wrong platforms?
The best solution will be if you create an API backend for your app that in turn talks to your app-server and database. This is the standard practice of creating mobile applications that have cloud backends
AWS API Gateway would be a perfect fit for it. This is very cheap, responsive and a secure service.
Is encryption out of the question? You can encrypt/decrypt strings or data between android and PHP.
Some codes that I used can be found here: https://stackoverflow.com/a/20929131/7199177
You might have created APIs using PHP
You can develop the following mechanism using the PHP to secure your APIs:
list out the API which should be public like login, signup so anyone can access it.
All other APP should be accessible after a some authentication only.
Your APIs should be talking to your Database server which is in a private subnet.
Other options:
Use API-Gateway with Lambda and your Database server:
To reduce the use of API-gateway you can directly write a code in lambda and use aws-sdk in your application to call lambda. In backend use your database server.

I am using Laravel in order to make a DBMS for a social network. I need it to make an app. can anyone tell me how? i cant find anything on google

Using Laravel for PHP and DBMS. How do I make an app? (for social networking).
I have googled most of the things but I am really an Amateur and need help.
There are many kinds of apps, so before you start to work on your app, you need to carefully determine what exactly you need. You could write desktop apps for various operating systems, or native mobile apps, or hybrids, or a web application... You name it. Anyway, Laravel is the server-side and it should be as agnostic to the apps as possible. You need to create an API and handle the following things:
CRUD for the database
session (log in, log out, register, password change, user settings)
logical API functions
file transfer protocol usage
push notification (if needed)
As per your requirements, you will need to implement the server-side API in Laravel, which is a PHP-based framework and use an RDBMS, which could be MySQL, SQL Server, Oracle, or a NoSQL database, for instance MongoDB.
Before you implement any apps, you should have a proof-of-concept for the API. You should not invest too much time working out the details of the API, as when you are going to work on a real app, you will notice things to be changed anyway. The API should be accompanied by a playground for testing, maybe a very small app without design where you could send requests to the API. Or you can implement a WebSocket API to have a single, duplex connection. It is up to you.
As about how to write an API, there are many tutorials.

Azure with API for WPF and javascript

I want to create following project :
Server application hosted on Azure - it connects to databse via Entity framework and gives and API for anyone who want to connect (but with account stored in SQL database)
WPF application - it consumes server methods, objects etc.
Web app (php & javascript) - also consumes server methods and object etc.
IMPORTANT : I have only azure student's subscription and I want to hold onto it - buying anything else is out of the question unless it has strong argumentation.
I figured that to do this I have to create REST Web API because I have no other choice to connect to server than via HTTPWebRequest (because I want to have the same API for WPF nad web app).
My question is : does better solution exists?
I think I can create different API's for desktop client than web app but I have no idea how to do that. Whould you be so kindly to show me other way?
Why dont I want to have this solution?
Reason is simple. For big databases and slow internet connection it would take ages to download whole data in few seconds. As far as my knowledge goes there is no lazy loading in REST thus my WPF application's thread reponsible for downloading database would freeze for a big period of time.
If my question is too broad please leave a comment before you put up a flag.
Also, any tips regarding my project design are well appreciated.
Different APIs for Desktop and Web: this can be done easily enough. Assume you have a class library to contain your business logic (domain stuff). Create a web api project that makes use of it, then create yet another web api project separately that also makes use of the core models. When you deploy, deploy each separately to a different domain/subdomain (I'm unsure if you'll require further Azure resources for this, but consider api.desktop.myapp.com and api.web.myapp.com... no real technical reason why you can't do it that way, though for architecture reasons I'd avoid it (it's really coming close to if not definitely is duplication of code).
Same API for Desktop and Web: you stated that you thought you'd have to do this differently for the desktop and web, specifically because of the resource usage on the server. I disagree here, and think you should implement some standardized rate limiting into your API. Typically this is done by allowing only X amount of resources to be returned in a single call. If the initial request asks for more than X limit, an offset/nextID is returned by the API, and the client submits a new request noting that offset/nextID. This means you have subsequent calls from the client to get everything it needs, but gives your server a chance to handle it in smaller chunks (e.g., check for rate limits, throttling, load balancing, etc). See the leaky bucket algorithm for an implementation that I prefer, myself: https://en.wikipedia.org/wiki/Leaky_bucket)

Sync Mobile App and Web App without third party services

Currently building a hybrid app. using Ionic Framework with PHP for backend services
I am having a case where a user has got his profile in Web app and Mobile App as well.
If the user adds two stories as favourites (Its kind of a reading app) from his mobile app or Web app,how do I sync that?
Here are the scenarios:
1) User marks the stories favourites from web app and when I come online through mobile app, display it.
2) User marks the stories favourites from mobile app when he is offline(Now this will be stored in LocalDB). So again when he comes online sync with the server?
I know there are services like Firebase which provides syncing service.
But What If I would want to develop a Custom Syncing service on my own for my application? Is that an extremely complicated process?
If yes and it can be developed ,then how should I proceed ? A basic idea? What are the best practices that I should consider?
Any links would be appreciated?
I know some of the comments recommended CouchDB in combination with PouchDB. That is a much better solution than trying to implement your own synchronization service with MySQL.
However, since you're using Ionic Framework you can also use Couchbase. Take the following example application:
https://github.com/couchbaselabs/TodoLite-Ionic
If you chose this solution you would have three moving parts. You would be replacing MySQL with Couchbase Server and running the Couchbase Sync Gateway to orchestrate any data between the device and the server. You can still keep your PHP backend if you have a web version of your application as there is a PHP SDK for Couchbase.
Two write-ups on this can be found here:
http://blog.couchbase.com/using-couchbase-in-your-ionic-framework-application-part-1
http://blog.couchbase.com/using-couchbase-in-your-ionic-framework-application-part-2
In the long term, you're going to find NoSQL much more pleasant to work with when it comes to APIs and mobile than MySQL.
Can be useful to write a POST method on the backend that receives the data from your local from the app and some user data (session, access tokens and other thing you considered neceasary). On the body for the request you include the data needed to be synced. The backend takes the body. Parse it and rreturn a result (http code) Based on that you can decide if the app should delete the local data or only mark it as synced on the local database

Which is the best feasible solution for sharing the data from the database?

here is my scenario, i am building a web application using PHP and MySQL. basically it is a real estate application. where i would like to share the data among several other platforms and devices, here is i what i intend to do
a) building the web app to be used with the browser using PHP, MySQL, and AJAX. (this will be my server)
b) extend the support and build a desktop application using POKKI.
c) extend the support and build an application for Androids and iOS devices.
d) all data transaction for the app should take place from the web server.
e) basically it will be server client application . where the server will be my web server and the clients will be iOS app, Android App Pokki etc.
i am not a hardcore programmer, although it has been more then 1 year since i started using PHP, and i do understand it to my use. i would like to know the best feasible solution on how to share the data among the different clients(POKKI, iOS App, Android App).
i would like to know.
a) do i have to connect to database directly from the client and access the data? is it possible? is it bad if i go this way?
b) do i have to create a public class with api sign up process? what would be the real scenario if i would like it to make it cross platform.
A Humble request to all of you to guide me on how does this things works. any articles, resources, links that can prove useful to me will also be appreciated.
thank you.
I think you should create an API which allows you to access the database strictly as you want it. Look at the twitter API for example and see how it allows third parties to access their data using simple requests.
So your site uses the DB directly where as all other applications you want to make will use the API ( which runs on ur web server)
This would allow you with the flexibility to have control who gets access and who doesnt ( only your own apps or even third parties etc etc) and allows you to build kick-ass applications without putting your actual database at risk.
Hope this helps!
1 - you should not allow client to access data directly - bad.
2 - sign up are easy with open id, let google or any other openid provider handle authentication, you deal with your own clean code without worrying about auth.
http://code.google.com/apis/accounts/docs/OpenID.html
You can create xml api and share the data from your server.
On different type of client you can eaisly parse the xml data and process it or show it.
In xml API if you want the restrict access then your can provide the restriction.
Please let me know if you have any issue
Thanks and Regards,
Ankur K Singh
take a look into getfrapi.com for building API.

Categories