Spring MVC ,JSON,#RequestBody android as client - android

Here my requirement is getting data from android client and posting those values to the database.Middle level layer is Spring MVC.How to get values from android client to web service? I already have done sample example that is with normal rest web service.I resolved it by using MultivaluedMapping.How to do it in Spring MVC.
Thanks for your valuable suggestions in advance.

Spring Boot makes what you want extremely simple, as 1) it handles most of the configuration automatically (for example it ads Jackson 2 to Spring MVC for seamless JSON handling), 2) it has awesome defaults that meat the needs of RESTFul web services.
Check out the guides section from Spring's site and more specifically the following ones:
1,2,3,4,5

Related

RESTful Client Verses normal HTTP Client For Android?

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 :)

How does android retrieve data from a website?

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

How Android POST to Django Rest Framework Json or API?

I have a web written in Django framework and created Rest Framework for the API.
I am required to write an android application based on the Django framework (Android and Django newbie).
However I do not know how to pass the data from android (user input) into database MYSQL through Django Rest Framework. I done a lot of research in past 2 weeks, but still I cannot see any solution (text tutorial, video tutorial, code example) related to this issue.
Note: I will not using any PHP script and looking forward integrate with Django Rest Framework.
Let's have a testing example API from Django : http://json-api.jerel.co/entries
User input field from android: blog, headline, body text, pub date, mod date, authors
Which class/library in android involved? Volley? httpUrl? Json?
I appreciate that anyone can share a simple code to get this done.
======================================================================
FYI,
Database: MYSQL
Server : CentOS
Web : Python - Django
Android : Android studio
============================================================================
After tried all the solutions on net, and excluded those apache http client deprecated post, this is the workable and simplest solution (in my opinion):
https://stackoverflow.com/a/33937147/2466516
Thanks to Nitro.
#chan-hau-yeen, you will want to look at something like Retrofit2 for Android to handle the network post to your Django backend. You can create json objects to post to your backend. Then with django you can accept the json and handle it there.
Once you have created api end points using DRF with data in json . You can use volley library for handling network calls .
Here is the link which shows how make network calls and json parsing .
http://www.androidhive.info/2014/09/android-json-parsing-using-volley/

What's the right way to organize cross-platform oriented web-service?

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.

How to connect android to python web services and MySQL database

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.

Categories

Resources