Android and RESTful service

I am trying to implement an application to use the RESTful web service. I studied several different examples and encoded a good working application that successfully uninstalls from the REST service. But now I need some direction. Here's some basic background (very simplified) ...

  • Suppose the underlying REST service has the GetReferrers and AddReferrer methods.
  • Of ActivityI call managedQueryto get Cursorback from ContentProviderfor mine ListView.
  • ContentProvider returns any local data and calls the asynchronous GetReferrers to get the latest list of source servers.
  • I have a custom ResponseHandlerone to parse JSON and paste it into ContentProvider.
  • I am currently deleting all entries in local ContentProvideron successful “retrieval” from the server, and then inserting a new / updated list into the database.

I have two questions ...

  • When I make a new GET, would it be common practice to delete all existing entries in the local ContentProviderand insert a new list? Or would it be better (albeit longer) to check for new / changed / deleted records just to add / change / delete, respectively?

  • I really don't know where to start the “add” from the client to use the REST method “AddReferrer”. I know how to add a new item locally in ContentProviderusing ContentValueswith getContentResolver().insert(). But, where would I put the code to push it to the server? Or would it be more common practice to skip the add to local ContentProvider, push it to the server, and then let GET get it back to local ContentProvider?

Hope everything makes sense. I would be grateful for any direction that you can give. If anyone knows of a good two-way example of how this is, please share. All the examples of REST client operations that I have found so far simply do "get" from the server and do not drop backups.

+5
3
  • - , REST, getReferrersSince(timestamp), . , . , , , , , .
    : . - GET http://.../referrers?since=[timestamp]

  • : ? "" (, SYNC_STATUS). , REST "".

+2

, № 1 , -. , , ( , - ), // , , - , "SET/WHERE" , .

, , //, , , , .

№2 XML , , :

Android Post Example

URL, .

:

http://www.example.com/MyWebService.asmx/AddReferrer?variable1=foo&variable2=bar&variable1=foo2&variable2=bar2

, .net-. .net variable1, DB, ​​.

[WebMethod]
public string AddReferrer(string[] variable1, string[] variable2)
{

, !

0

You should not have verbs in the method names. On a RESTful system, "action" is implied with the verb of the http request. AddReferrer should be called "referrers" and should be called using the PUT http method. Check out the following article http://www.infoq.com/articles/rest-introduction

-1
source

All Articles