Python API URL Cascade build

Source: Internet
Author: User

Refer to the company Python talent RPC interface Cascade API call

Rpc.api.users.list ()

Rpc.api.login (username= ", password=")

rpc[' Api/users ' (id=222)

Wrote a Demo,python is really concise, less than 30 lines of code to fix

#Coding=utf-8classNamechain (object):def __init__(self,prefix,callback): Self._prefix=prefix self._callback=Callbackdef __getattr__(Self,item): Next_prefix= Self._prefix +'/'+ItemreturnNamechain (next_prefix,self._callback)def __call__(self,**kw): Self._callback (self._prefix,kw)def __getitem__(Self,item): Self._prefix=Itemreturn SelfclassService (object):def __init__(self): Self._api= Namechain ('API', Self._invoke)def_invoke (self,method,params):Print '******************'        Print 'Invoke Method:', MethodifLen (params) = =0:Print 'params is empty'            return        Print 'params is'         forKvinchParams.iteritems ():PrintK':', v @propertydefAPI (self):returnSelf._apis=Service () API=S.api#Call mode onePrint 'Call mode one'#api/usersapi.users ()#api/user params {"id", 111, "name": "Leslie"}Api.user (id=111,name='Leslie')#Pai/user/tagsapi.user.tags ()#api/user/tags/list params {"id", 111, "session_id", "Love You Forever"}Api.user.tags.list (id=111,session_id='Love Forever')#Call mode twoPrint 'Call mode two'api['api/users'] () api['api/users'] (id=111,name='Leslie') api['Api/user/tags'] () api['api/user/tags/list'] (id=111,session_id='Love Forever')

Python API URL Cascade build

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.