DemandsHTTP 服务器客户端
Demands 是一个 HTTP 服务器客户端。
代码示例:
from demands import HTTPServiceClient class MyService(HTTPServiceClient): def get_user(self, user_id): return self.get('/users/%s/' % user_id).json() def safe_get_user(self, user_id, default_user): response = self.get( '/users/%s/' % user_id, expected_response_codes=[404]) return response.json() if response.is_ok else default_user service = MyService(url='http://localhost/') user = service.get_user(1234)
评论