Reputation: 4818
I am trying to communicate to my server using Android Application. I googled it and get to know about REST API. I followed the article http://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-12-2/, and wrote backend code.
As far as I know, what I got is nothing but backend code, which manages various responses from the user. Earlier, what I doing was, coding manually like this:
public function add_data()
{
// Adding data to the table using this controller.
if ( isset($_POST['submit']))
{
if ( isset($_POST['heading']) && isset($_POST['content']) && isset($_POST['references']))
{
// echo "I am in post";
if ( !empty($_POST['heading'] && !empty($_POST['content'] && !empty($_POST['references']))))
{
$this->load->model('Admin_model');
$this->Admin_model->insert_data($_POST['heading'],$_POST['content'],$_POST['references']);
// echo "Data is inserted successfully.";
}
}
}
$this->admin();
}
What above code does add data to the database.
Now, I want to know how the REST API coding is different from the backend coding in a framework ( Say code igniter, in case of PHP)? The backend coding gives output in json form.
What are some better ways to communicate with the server in android application?
Please help me.
Upvotes: 2
Views: 4486
Reputation: 483
Frameworks like codeigniter and Restfull "backends" are not mutually exclusive. You could in fact write a RESTful API that takes advantage of CI.
CI's typical UI structure is segmented as follows...
example.com/class/function/ID
There is no reason why you can't use this std structure to implement a RESTful API. Though using CI is probably overkill.
Example CI REST Implementation
(Check out the README on this site. Has some great examples plus a tutorial that might help you understand how to move forward)
As far as communicating with an Android application using a RESTful API is a great option since it means your application doesn't need to be aware of the servers underlying technology and therefore you gain some flexibility in how you manage your system/code.
Alternatively you could look into using other protocols such as Sockets. There are numerous options for implementing Sockets for different languages and frameworks.
If you take this approach I would suggest ditching PHP.
Upvotes: 2