开发者

RESTful - URI definition of sales transaction

I´d develop some Restful services in my application, like (URI):

xxx/method/blah
yyy/method/bleh
zzz/method

all of these resources (xxx, yyy, 开发者_JS百科zzz) are specifical products in my business and now i need design the sale definition to them. I think in:

xxx/sell
yyy/sell
zzz/sell

But it looks like to me not cohesive because i think that the sell behaviour should be an unique and specifical resource, like:

transaction/sell/xxx
transaction/sell/yyy
transaction/sell/zzz

What is (should be) right here for you?

Thanks.


To be RESTful, you want the verb (eg. "sell") to be the HTTP method. The URI should identify the resource, not the action to be taken on the resource.


I think you are trying to decide between functional oriented design (where the function, sell, is in the center, and it perform actions on different entities, the products) and object oriented design (where the object, the product, is in the center, and each object has method, such as sell).

There is no "right" and "wrong" answer here - it really depends on you language paradigm. So, I think you should confirm with the language you are implementing the service: If it is an OO (Object Oriented) language (and most chances you are using an OO language), you should use the OO approach.
In Java+RESTEasy (for instance) the implementation approach is quite obvious:

@Path("product")
public class Product {
    // Product fields
    // ...

    @Path("sell")
    @GET
    public void sell(){
        // Selling implementation
        // ...
    }
}

The RESTEasy framework will translate the request of http://.../product/sell into invocation of sell() on an instance of product object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜