java - Need sample Android REST Client project which implements Virgil Dobjanschi REST implementation pattern -
i want build rest client on android phone.
the rest server exposes several resources, e.g. (get)
http://foo.bar/customer list of customer http://foo.bar/customer/4711 customer id 4711 http://foo.bar/customer/vip list of vip customer http://foo.bar/company list of companys http://foo.bar/company/4711 company id 4711 http://foo.bar/company/vip list of vip companys
i (think) know how talk rest server , information need. implement rest client class api this
public list<customer> getcustomers(); public customer getcustomer(final string id); public list<customer> getvipcustomer(); public list<company> getcompanies(); public customer getcompany(final string id); public list<customer> getvipcompanies();
referred presentation "developing android rest client applications" virgil dobjanschi learned no idea handle rest request in worker thread of activity. instead should use service api.
i idea of having singleton servicehelper binds (local) service afraid did not understand service concept correct.
for not understand how report rest call result (done asynchrounous in service) caller activity. wonder if need 1 service handles rest requests (with different return types) or if need dedicated service each rest request.
probably have many other understanding problems best thing me sample application meets needs. use case not unusual , hope there in example application out there.
would please let me know!
any other suggestions points me in correct implementation direction helpful (android api-demo not match use case).
thanks in advance.
klaus
edit: similar topics found on (after posting this) lead me in direction need (minimizing complex "dobjanschi pattern"):
overview
edit:
anyone interest consider taking @ restful android might give better it.
what learned experience on trying implement dobjanschi model, not written in stone , give overview of might changed app app formula is:
follow ideas + add own = happy android application
the model on apps may vary requirement might not need account syncadapter other might use c2dm, 1 worked might someone:
create application have account , accountmanager
it allow use syncadapter synchronized data. have been discussed on create own syncadapter
create contentprovider (if suits needs)
this abstraction allows not access database goes servicehelper execute rest calls has one-per-one mapping method rest arch.
content provider | rest method
query ----------------> get
insert ----------------> put
update ----------------> post
delete ----------------> delete
servicehelper layering
this guy basicly start (a) service(s) execute http(not protocol it's common) rest method parameters passed contentprovider. passed match integer gotten urimatcher on content provider know rest resource access, i.e.
class servicehelper{ public static void execute(context context,int match,string parameters){ //find service resource (/path/to/remote/service match //start service parameters } }
the service
gets executed (i use intentservice of time) , goes restmethod params passed helper, for? remember service run things in background.
also implement broadcastreceiver when service done work notify activity registered broadcast , requery again. believe last step not on virgill conference i'm pretty sure way go.
restmethod class
takes parameters, ws resource(http://myservice.com/service/path) adds parameters,prepared everything, execute call, , save response.
if authtoken needed can requested accountmanager if calling of service failed because authentication, can invalidate authtoken , reauth new token.
finally restmethod gives me either xml or json no matter create processor based on matcher , pass response.
the processor
it's in charged of parsing response , insert locally.
a sample application? of course!
also if interesting on test application @ eli-g, might not best example follow service rest approach, built servicehelper, processor, contentprovider, loader, , broadcast.
Comments
Post a Comment