I have an online mysql database. I understand that to connect to it from an android app, I need to use a REST web service. From what I understood until now is that I have to use a REST webservice + JSON and Jquery to handle everything. But the things that I dont understand are:
do I need any coding to be done on my mysql web host domain?
this REST web service needs to be coded within my android app?
Do I need an apache http client, and that needs to be coded on my app or on the web host?
You're confusing database access, server side code and REST.
It is best practice not to go around directly connecting to databases from a client, especially a "locationally diverse" one.
Your architecture may look like
Android app ---HTTPS REST Verbs---> RESTful Webservices on server, hosed on Apache, Tomcat etc. --- Data access, be it via PDO, JDBC, JPA, whatever ---> mySQL.
The RESTful part really is optional, you can call into whatever you like if you're using an URL.
Related
May be my question is a bit ambiguous so I'll try to explain it clearly:
Normally I work with ASP.NET MVC and write back-end for the websites. So 99% of data comes from the user's input to forms and sent to views.
Now I would like to implement web-service based on ASP.NET : here what I want to do:
My mates write the same application on Android and iOS. I write web-site with the same functionality. The applications collect some data (inputs, Geo-locations, etc.) and should send it to the common DB (SQL Server).
Respectively, web-service should send back some data.
I have no experience of writing service that get and post data to different platforms but have some idea how to do it: JSON or XML supported by all devices, so before post-get process I should convert data (no matter CLR, JVM, iOS) to JSON/XML and get\post (send, recieve) it.
I want to do it with hosting the server on Azure.
Could you prove that I am thinking on the right way or show what mistakes did I do? Is there any topics I need to learn?
More clearly, here are the questions:
What should I learn in order to implement it?
Is it good idea to use Azure\SQLServer with Android\IOS?
Will I need to write my own API or there are ready solutions for cross platform communication (data-exchange)?
You should learn ASP.NET Web API and not use a ASP.NET WCF web service. WCF is not cross platform compatible. Web API is because it is compatible with the REST (representational state transfer) architecture and all the platforms you mentioned can use REST for their calls to your RESTful API.
I don't see any reason why you shouldn't use Azure if that's what you're comfortable with. The Android\IOS applications will be talking to your RESTful API so the backend you use is not relevant to the consumer of you API.
I'm new to Android and to web services in general.
This is what i gotta do: My company has a back end website(for the client to monitor the sales) that's used to manage/monitor sales on some stores and it connects to a MySQL db to store data about sales and users(usernames and passwords).
What I want to do is to get data from that database and to add (sync operations) new rows, all of this from my android app.
I googled this many times and it came up with some similar projects but using another languages.
I would like to see some code samples if possible and some how-to theory, what theory should I follow when developing this, how and what ways of communicating between android and python web services and from the web services to the MySQL database.
Thank you in advance.
You will need a working API, that allows you to communicate to the web service from the android application. I would read into how to write an API and how to build a RESTful service using JSON as a way of communicating between server and android app. There are alternatives to JSON, but JSON is better suited for Android than perhaps AJAX and soap is being used less and less. (Can ajax call be done in Android? It can but has limitations)
(I could only post two full hyper links as i don't have enough reputation yet to do so, you may have to remove the spaces)
API:
http://sharismlab.com/blog/2012/07/21/how-to-write-an-api-for-your-web-app/
REST:
www .restapitutorial. com/lessons/whatisrest.html/
JSON:
htt p:// www.r evillweb.co m/article s/why-use-j son/
You may want to check out restjee. It allows you to define and implement RESTful data access APIs without having to write any server side code. Works with just about any database.
I have experience building android applications but now I would like to start building applications that interact with some sort of web database to push and pull data.
What type of database should i set up on a remote server for my application to interact with? From what i understand I need a database on the remote server and some service that my android app can communicate with?
What can i read that will clear up how this works and how i can get started?
The easiest (and often most flexible) combination in my opinion is PHP and MySQL. PHP as the scripting language which is called (via http) from the app, and handles all the database access. MySQL as the database. PostgreSQL is also an option for the database, of course. And if you have access to .NET, JSP or something like that, that's also an option. But a web server with Apache, PHP and MySQL is free, powerful and easy to maintain, and most/many web hosts have them.
The way it works (which is the same no matter what kind of webbased services/servers you chose), is this:
- The database is installed on the server
- You have a web area (on the web server) which has access to the database (this is how it will be with a typical web hotel solution)
- You place your scripts (f.ex. PHP) in the web area
- The web scripts access the databse, with functions for fetching and/or storing information
- Your app uses httpclient or something similar to send http GET or POST requests to the PHP scripts, either sending information or asking for information, or both
It's also quite possible to write database access code directly in your app (this is very easy in Java and C#, compared to languages like C og C++). However, most hosts don't allow remote access to their database servers, so you'd most likely have to set up a database server yourself. Also, accessing the database server directly is a security risk, and I wouldn't recommend it.
As to what you can read, there's lots and lots of tutorials, howtos and concrete examples on the net. Search for "php access mysql databse", f.ex., for ideas on how to write php scripts that handles the database transaction(s). If you have a more detailed decription, I might be able to point you to something more specific.
I strongly suggest adding web service layer between your application and database, using i.e. JSON or XML. Exposing DB directly ma be security risk and is rarely the way to go.
I want to implement a RESTful webservice for an Android App using JSON. Do i need something om my server running to make for example a GET request work , like with SOAP is the case. I have read something on servlets but i don't know if this is neccesary or not.
If you will be using PHP on the server then you can write a RESTful service with a PHP application framework like Kohana, CodeIgniter, CakePHP etc. There are quite a few.
These frameworks have built in functions for encoding results in JSON format and they support the REST approach out of the box.
If you prefer I'm sure there are also similar IIS and .NET based approaches too.
If you query your own server, then you need to first program your server to handle requests. On the other hand, if you query a 3rd party RESTful server, then all you need is create the appropriate http request, send it and handle the response.
Servlets are used for Java EE based implementations of servers. You can implement your server in any programming language or framework you want.
I'm planning on writing an android app that can view and update data on a local network Oracle DB.
I have already written a python script which checks the oracle db every couple of minutes and writes out XML files which I then plan to parse through my android app to display the data.
As I mentioned though this will only work if the android device is part of the same network (either connected locally or through a vpn), and the XML will be stored on a Unix server.
The question is how to access that Unix server with the android app? Can I use FTP via an android app, or should I be looking to change the python script to send the XML to an easily retrievable location?
EDIT To clarify what you mean, you have a web service running on something like tomcat, the client sends a request to get the data from the oracle db (can also use some form of authentication), the web service responds and sends the data in a format (XML, JSON etc.), the client then sends a request back to the web service to change some data on the oracle db, and in turn it does the clients bidding?
Normally you would create a web service to provide data to mobile clients. There are several reasons for this:
Web services are accessed via HTTP/HTTPS which is a standard protocol and is guaranteed to work on all networks. Corporate wifi networks are especially notorious for locking down protocols except for web and email.
Web services compared to static XML files have an advantage of creating response on the fly. Which means that data will be current.
Web services can take some input parameters and create response based on this parameters.
Authentication: it is a common approach to implement username/passord authentication in the web service, especially if you serve some private data.
Update:
REST is a very popular type of web service. Look at some implementations in Python: Recommendations of Python REST (web services) framework?
This book helped me a lot: http://oreilly.com/catalog/9780596529260
REST is a way of designing your web service. Folks much more intelligent than you and me have divined that all of the work needed for something to work on the net can be handled through a combination of HTTP status codes, HTTP verbs like POST, GET, DELETE, PUT etc. and a clear hierarchy of resources (nouns). It sounds very limiting but it's quite beautiful when it all works together.
Have a look at the Facebook Open Graph API (developers.facebook.com) to get an idea of what a proper REST service looks like.