as the title said,
I'm looking for a method to handle a POST request made from my Android front end to my Drupal back end.
I've already seen a lot of documentation and reference, like this one: http://tylerfrankenstein.com/code/build-mobile-app-sell-products-with-drupal
but I can't figure it out.
Anyone can help me?
Use Services
It sounds like you need to setup an API using something like a REST service. Drupal has a great module for this called Services.
Essentially you can setup your Android app to use the POST method to push to your Drupal configured endpoint.
EG: https://www.mysite.com/api/android/
Services is extremely flexible and you can have it work through basic CRUD operations for nodes or you can use hooks and use custom logic for a particular service you want to use and write custom PHP code to do whatever you want.
How about using this library for native Android applications to communicate with Drupal web servers?
Feature list:
Synchronous and asynchronous requests
Flexible object serialization / deserialization
API can calculate object differences to perform patch requests
Simple entities request
Related
I am developing an Android App. I read about RESTful Webservices and decided to use that for my app. But I have doubt about REST Client
After reading many article I understood that
I can directly write code to make HTTP request from android
App as given in Connenting To Network OR
I can write code to develop the RESTful client OR
I can use some already developed Third Party lib like RESTDroid
I am not able to decide should directly write code to make the HTTP request as suggested by developers guide or i should follow the rest client model.
What is the advantage of using rest client over directly making HTTP request ( or can say using non-RESTful Client) ?
I am new to android and REST architecture. Please correct me if I am wrong.
This is quite a broad answer but I will divide it in 2 parts:
1) Rest and non-Rest clients:
In my experience I have not seen any REST client except the browsers
the industry trimmed part of the original REST specification and created improved HTTP clients/services and called them REST which(most of them) are not different than any ordinary HTTP library.
So for Android you will get ordinary HTTP Clients with various features but the REST part you will need to code it yourself.
2) What is better to use
Clearly I would not advise to write your own HTTP client as it is far from trivial job to do.
I would not advise to use Retrofit for a really RESTful service as it is not good for that. You better build something on top of OkHttp or extend Volley or Jus which is my creation and it will support basic HATEOAS implementations from version 0.7.0 and optimized pipeline and memory utilization from version 1.0.0 (follow it on github :)
I'm new to android, I'm trying to build an android app that is a front for a web portal. For example, Airbnb. They have a website, but they also have an android app that, using it's own layout, will show listings from their website.
There are many websites that teach how to or even directly convert your website to android apps. However, this will result in an app that loads too slowly and is unresponsive due to CPU usage.
Could anyone share any tutorial/guide to learn how to do this myself?
Million thanks.
To actually load data from a web server you're gonna need and API which usually delivers the proper date using JSON or XML format so that you can properly parse and display that data. Building this API is in it self a complete course on its own.
But connecting to and requesting data from the API is usually done using some networking libraries. These are some of the better know libraries for this purpose.
OkHttp: A complete library with a set of tools for handling network connections and HTTP requests.
RetroFit:Type-safe HTTP client for Android and Java by Square, Inc. which is built on top of OkHttp.
Async-Http-Client:
The Async Http Client library's purpose is to allow Java applications
to easily execute HTTP requests and asynchronously process the HTTP
responses. The library also supports the WebSocket Protocol. The Async
HTTP Client library is simple to use.
There tons of other good libraries.
its called webservices
Through android you get data in form of json from a web server and then return in custom view as you want.
Follow this link hope it will help
Step by Step Method to Access Webservice from Android
you would have to write an API/Web service or use if already exits to fetch data from web server. Basically the concept is that, the website itself must be pulling data from some database, so write an API which would fetch the data from same API and return JSON data and consume the API from your android app.
If you know PHP refere to this for the help :http://www.codeproject.com/Articles/267023/Send-and-receive-json-between-android-and-php
You can write WebService, in programming it generally refers to a web page(ex. Airbnb), that can be called from your android application which can pass in data to it, or receive data from it.
WebService is basically like a 'method' or 'function' in a normal programming language; except you're calling it over the internet.
The first thing is you have to create a Web Service. The Web Service will be your "bridge" to consume the data from other Website like airbnb or others and return the data to your android through json format for example.
You can create a Web Service using many languages like C#, Java, PHP, etc. I would like to recommend you to use the language that you know the most.
You can try to google this
Cheers
I'm using AsyncHTTPClient to communicate with my server API.
I've read that I have to use services to communicate with a server.
1) Is AsyncHTTPClient already a service? Or do I still need to put all methods which use AsyncHTTPClient into my own services? Or is it OK to call AsyncHTTPClient methods directly from my Activities?
2) I can't understand how services should be properly used. Let's say I don't use AsyncHTTPClient but I have few different actions which make a call to server API (get realities, get users, post user, etc.). Do I have to put each action into a separate service? If not, how can I call different methods from one same service? All examples I have seen always show that there's just one action which is automatically being called on service start up by Activity.
3) I found another Android REST library Retrofit - does it have any advantages over AsyncHTTPClient? Do I need to put it into services?
At first, I would recommend you to use Retrofit. I've already used AsynHttp, but now I am using Retrofit, and I am very satisfied with it.
About the topics in your question:
I've read that I have to use services to communicate with a server.
Where do you read this? I don't create Service to my requests, and all of then works pretty well. The main point when creating your requests is to make them in a background thread. So if you don't use some lib like AsyncHttp or Retrofit, you have to put your requests in an AsynTask class, for example.
Is AsyncHTTPClient already a service?
No. It is a library to make asynchronous HTTP requests. In the site of the lib, they say:
All requests are made outside of your app’s main UI thread and You can also use it in Service or background thread.
That is, you can use it in a Service, they do not say you have to use it in a Service.
The example in the site teaches how to make a RestClient with this library. It is a good example. You only need to create a static class and put the methods to make your posts, gets etc
I can't understand how services should be properly used.
Services are used for long-running operations in the background. A possible way to use a Service with your lib (AsyncHttp or Retrofit) is when you want to make requests to the server, even when the user is not using your app. So you can create a Service with a timer that will call the server at the intervals defined by you.
Retrofit - does it have any advantages over AsyncHTTPClient?
Backing to Retrofit, again you don't have to put it in a Service. Only if you need this. From threir site, they say: Retrofit turns your REST API into a Java interface. This make your client very simple, and self documented because each call to your server API will be a method in this interface, and I think this is a big advantage. It is simple to use Retrofit. As I said, now I changed to Retrofit, and I can say, the lib has a good documentation and support, it has many users. So it is easy to find solutions to some bug. Other advantage is that it already has the lib GSON, which is very useful to parse the JSONs that you will receive from your server API.
But of course talking about vantages is dangerous because you can find many personal opinions. See this question and its answers. I think some answers from there can also help you with your choice.
To finish, here are some links with tutorials about Retrofit and how to create your requests with this powerful library.
Durable Android REST Clients
Consuming APIs with Retrofit
A smart way to use Retrofit
Im developing an app that have alot of web requests. Such as download or upload files , REST requests and etc.
I want to save all of this functions in a class like a helper and only just import the class and call functions that i need them in my activities.
something like a custom library for web requests i mean.
Is there any Design pattern for this?
(I hope i explain my idea well)
Consider using these libraries:
Robospice - for asynchronous network calls
Retrofit - for REST calls
OkHttp - good HTTP/SPDY client
Picasso - for image loading and caching
Jackson - to work with JSON
You can use custom IntentService class to hanle all networking there, starting this service from UI and passing apropriate ACTION to perform.
And of course i would suggest you watch this video from Google I/O 2010 and use REST Pattern A described there in EVERY network app you make.
You could use the Chain of Responsibility pattern for building up requests and then executing them. See some details here.
Of course, using just this one pattern would not be enough. It should be used in conjunction with an Observer, Factory, Proxy and maybe some others. Just start developing with SOLID in mind.
I have to implement a client-server architecture where there are many android client located at different places querying the application server (running all the time (24x7)) and which will do task accordingly and reply to clients. But I don't know what exactly application server is and how to implement it and what is easiest and quickest way to implement this. I am running out of time that is why posting this question otherwise I would have gone through lot of tutorials instead.
The server code is to be written in php/c#/java.
Any quick help is highly appreciated.
You may have look at Google App Engine its easy to setup, hosted on google environment. Which might fulfill your need. In this case you don't need to buy hosting plans etc. etc. You will get yourappname.appspot.com URL to use app server.
Hope it helps!
Note:
Appengine supports Python and Java
You can implement it by knowing how the application servers work.
First of all, you should create a class that implements the HttpHandler, in handle method you can get header and body of the message.
Secondly, you should choose how to handle the request in HttpHandler. One possible approach can be using of ThreadPoolTaskExecutor or SimpleAsyncTaskExecutor or any task executors.
Finally, you should prepare the response messsage with exchange.getResponseHeaders() and exchange.getResponseBody()