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.json
testfile.json has a json payload. I cannot send the content of Json file as body.
I have imported the HTTP libraries. But do not see any key-word to make an API call with file.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With