Hi!

Right now we use the networking layer like this:

client = getUtility(IRESTClient)

client.GET(url)
client.POST(url, data)

After a discussion with Locklainn if his UDPClient shouldn't rather be a connection and store it's socket inside the instance instead of passing it I was wondering if the same shouldn't be true for the REST client.

So instead writing it like this:

resource = IRESTResource(url)
resource.GET()
resource.POST(data)

(headers are in both cases optional parameters to the call)

This would have the following benefits:

- it models more what REST is about (you call a method on a resource)
- it models how Capabilities in pyogp are used already (they also have POST() and GET() methods and the capability basically is the resource).

How the resource get's instantiated in the above example is by using an adapter which adapts to a string (the url) for the IRESTResource interface. A factory utility maybe would be a different way of doing it:

factory = getUtility(IRESTResourceFactory)
resource = factory(url)

The first solution might be more flexible though if you want to instantiate a resource from something different than a string as in your client code you do not need to care. In the second case though if the url is not a string but some sort of object with an interface you would need to also change the getUtility call and use some IRESTResourceFromAnotherObjectFactory.

But what do you think of the general idea? I think it would make usage of resources and caps similar and you'd only need to learn once how you do GET and POST and the cap would be more or less a wrapper around the resource.

-- Christian

PS: Of course this means changing of code but it's pretty clear how to do that and it might show if all our tests really notice such changes. And we should try to refactor things where possible IMHO. Merciless refactoring FTW! :-)




--
Christian Scholz                          Homepage: http://comlounge.net
COM.lounge                                   blog: http://mrtopf.de/blog
Luetticher Strasse 10                                    Skype: HerrTopf
52064 Aachen                             Video Blog: http://comlounge.tv
Tel: +49 241 400 730 0                           E-Mail [EMAIL PROTECTED]
Fax: +49 241 979 00 850                               IRC: MrTopf, Tao_T

neue Show: TOPFtäglich (http://mrtopf.de/blog/category/topf-taglich/)

_______________________________________________
Click here to unsubscribe or manage your list subscription:
https://lists.secondlife.com/cgi-bin/mailman/listinfo/pyogp

Reply via email to