Difference between revisions of "Certified HTTP API"

From Second Life Wiki
Jump to: navigation, search
m (Client: Ha ha spaces)
(Client: Whoops, that wasn't python!)
Line 10: Line 10:
  
 
   
 
   
  def start_transferring_foo(*args, chttp_context):
+
  def start_transferring_foo(chttp_context, *args):
 
   
 
   
 
     # this context method saves away the non-deterministic thing
 
     # this context method saves away the non-deterministic thing
Line 23: Line 23:
 
  # and constructs a chttp_context upon invocation
 
  # and constructs a chttp_context upon invocation
 
   
 
   
  certified_http.resumable(start_transferring_foo)
+
  start_transferring_foo = certified_http.resumable(start_transferring_foo)
 
   
 
   
 
  # in python 2.5 you would precede start_transferring_foo with @certified_http.resumable
 
  # in python 2.5 you would precede start_transferring_foo with @certified_http.resumable

Revision as of 16:23, 13 September 2007

Certified HTTP API

This is the ever-evolving api for a Python implementation of Certified HTTP.

Client

Th major problem we face on the client is resumption. If you send a message, then you crash, what makes you not decide to send the same message with a new message-id? If you planned on sending a message, then taking some actions based on the response, how can you ensure that said actions get carried out on resumption? In the general sense, this implies that a certified http client must be able to capture and store a continuation.

There may be a way to capture a continuation automatically, but it seems unlikely that we'll be able to solve that problem in general, much more likely that the developer writing the chttp client will have to write continuation-friendly code. We need to have an API that allows you to conveniently store and restore the enough application state to serve as a continuation, and to unit test that you actually got all the state you needed!


def start_transferring_foo(chttp_context, *args):

   # this context method saves away the non-deterministic thing
   # during the initial execution, and spits out the saved value on subsequent runs
   local = chttp_context.persist(some_non_deterministic_thing)
   
   response = chttp_context.post(escrow_url, "start transaction")
   
   coupon_code = local + response['random number']

# this wraps the worker function with another whose signature is *args,
# and constructs a chttp_context upon invocation

start_transferring_foo = certified_http.resumable(start_transferring_foo)

# in python 2.5 you would precede start_transferring_foo with @certified_http.resumable

Server

The paradigm on the server is actually a little easier to conceptualize, since we already have a handle method on the server that we expect to be called asynchronously. We still have to be careful about relying on module-level objects and other external contexts.

class Resource(mu.Resource)

def handle_foo(self, req):
    # we're already in a chttp context