ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Passing data to RESTful WebServices

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing data to RESTful WebServices

    I'?ve been reading up on RESTful services and I'm a little confused on how data should be passed. Should data be passed in the Path portion of the URI or by using Query Strings?

    Most examples I've seen for a GET send the data as part of the Path in the URI. GET http://example.com/order/ABC/123
    Is sending the request using Query Strings acceptable? GET http://example.com/order?orderNumber=ABC&lineNumber=123

    If you are adding a record, would you send the data in the Path portion of the URI or would you use a Query String? POST http://example.com/order/ABC/123/PART-A/200/CASE vs POST http://example.com/order?orderNumber...200&units=CASE


  • #2
    I guess that depends on who you ask...

    If you want to be a purist about it, the URI should identify the thing you're working with, and the HTTP method should identify what you're doing to it. If you are using query string parameters, that typically means that the path is identifying which program to call instead of thing you're working with. (Not always, but it seems likely.) So you could argue that it's wrong to use query strings for this, it should be the path.

    But, there's nothing in the REST philosophy (and keep in mind that REST is a philosophy, NOT a standard) that says that. You could certainly opine that using the path is a better way to represent that you're working with a "thing" rather than pointing to a program and passing parameters to it... but others could opine that query string doesn't mean parameters, that it, too, identifies a thing. It's purely a matter of opinion.

    Also, an awful lot of people doing REST are not purists at all, and don't really care if they follow the REST philosophy. Basically anything where they call a URL and don't have to monkey with the overly complex SOAP protocol is "REST" to many people. Sure., it's technically not.. that in REST the method represents what you do, and the URL represents the item you're working on.... but then you get labelled a "purist" and many would argue that while that was the original definition of REST, it is no longer only that.

    So... it all depends on who you ask, and how much they care about the original philosophy of what REST means.

    Comment

    Working...
    X