• Post Reply Bookmark Topic Watch Topic
  • New Topic

RESTful API  RSS feed

 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

So, I have a string of number of any length like 231654894321. the object is very simple:


but how do I invoke scarmble()? what HTTP method and how should the URI look so it would be considered RESTful?
thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. REST is an architectural style not an API (but a REST toolkit may impose an API)

2. The HTTP method depend on what you are doing with the resource - GET POST PUT DELETE - all have separate implications

3. The URL would reflect how the server knows about the resource.

Bill
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, I'm doing scramble() on numberstring, so how should the URL look?
adding /scramble at the end ?
thanks
 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Spades wrote:well, I'm doing scramble() on numberstring, so how should the URL look?
adding /scramble at the end ?
thanks


Where is NumberString held in between requests?

Most RESTful services are stateless, so modifying something tends to require some form of identifier so the server code knows what thing to change.
If scramble() is some form of maintenance task (fire and forget, or similar) or general reporting then OK, no extra data is needed.

In essence what your endpoint URL looks like is defined by the task it is supposed to be performing. And that should be (IMO) defined without concern for the underlying existing code. Indeed, it should be defined before the code is written.
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
numberstring is persisted in DB, and yes, if you could see in the POJO structure, each numberstring has id.
thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Spades wrote:well, I'm doing scramble() on numberstring, so how should the URL look?
adding /scramble at the end ?
thanks


Does scramble modify a variable that persists on the server? That would be a POST
If not, I suppose it would be a GET since the resource is not changed.

Bill
 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, but what about the URI? do we append scramble at the end? I thought this is unRESTful? since scramble is not a resource, but a way to manipulate resource.
thanks
 
Tim Holloway
Bartender
Posts: 18715
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The URI can be anything. URL requests come into the server, the server matches them up against its webapp contexts to figure out which webapp will receive the request, then the webapp's web.xml is examined to see what servlet, if any matches the URI. If none do, the server resorts to its default mechanisms, trying for a JSP or a resource file. However for ReST, you're generally going to be sending it to a servlet. The servlet can then further dissect the incoming URL any way it wants to.

One of the easiest ways to get ReST running in a Java webapp is to use the Apache CXF library. CXF allows you to construct POJO objects to handle the requests and by annotating the POJO methods, to map a specific URI to a method. Like so:

 
David Spades
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah, my question was how the URI should look like. In your example, the URI will have /GetLastSyncDate, but there's no such resource with the name GetLastSyncDate. in fact, GetLastSyncDate is a method, not resource. My question is, is this RESTful?
thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see no reason to get picky about whether executing a method versus returning a variable is RESTful.

If the operation gives the same result every time then it is idempotent and a good fit to a GET operation.

Bill
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!