How to make a POST (ReST) API in Robot framework with

前端 未结 3 1811
孤城傲影
孤城傲影 2021-01-13 09:09

I need to replicate the below API call in Robot Framework:

curl -X POST \"http://xyz/api/createApp\" -H \"Content-Type:application/json\" -d @/tmp/testfile.jso

3条回答
  •  忘掉有多难
    2021-01-13 09:19

    Bulkan's robotframework-requests is nice. But if you can get by with less, you can do your own local lib/posthttp.py in a few lines like this:

    import requests
    import json
    
    def do_requests_post( url=None, data=None, headers={"Content-Type":"application/json"}):
        return requests.post( url, data=data, headers=json.loads(headers) )
    
    def do_requests_request( method="GET" url=None, data=None, headers={}):
        return requests.request( url, method=method, data=data, headers=json.loads(headers))
    

    Note that the return object is the rich-and-powerful "Response" which has member functions like .json() (which returns a dict if the .text is sensed to be JSON) and .status_code (int).

提交回复
热议问题