def service(self):
    '''Handle a request
    '''
    # The key is the request path
    key = self.request.url.path.strip('/')
    
    # Set content-type
    self.response.headers = ['Content-Type: application/json']
    
    # Standard reply
    rsp = '{"status": "OK"}'
    
    if not key:
      # Empty key means list all avilable keys
      if self.request.method == 'GET':
        rsp = json_encode({'keys': self.entries.keys()})
      else:
        rsp = self.method_not_allowed()
    else:
      # Non-empty key means manipulate the store
      # HTTP method defines the action
      if self.request.method == 'GET':
        # Read an entry
        try:
          rsp = json_encode(self.entries[key])
        except KeyError:
          rsp = self.not_found(key)
      elif self.request.method in ('PUT', 'POST'):
        # Set an antry
        self.entries[key] = json_decode(self.request.input.read(1024*1024))
      elif self.request.method == 'DELETE':
        # Delete an entry
        try:
          del self.entries[key]
        except __HOLE__:
          rsp = self.not_found(key)
      else:
        rsp = self.method_not_allowed()
    
    # Respond
    self.response.headers.append('Content-Length: %d' % (len(rsp)+1) )
    self.response(rsp, '\n')
dataset/ETHPy150Open rsms/smisk/examples/core/key-value-store/app.py/KeyValueStore.service