How to create a POST API (ReST) on a Robot platform using

I need to replicate the following 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 contents of a Json file as a body.

I have imported HTTP libraries. But I do not see any keyword for calling the API with the file.

+5
python robotframework
source share
3 answers

http://bulkan.imtqy.com/robotframework-requests/#Post has a file parameter. And what you can do is use the Get File keyword from the operating system library and pass that Post keyword.

+5
source share

Bulkan robotframework requests are good. But if you can get by less, you can make 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 returned object is a rich and powerful โ€œresponseโ€ that has member functions such as .json() (which returns a dict if .text treated as JSON) and .status_code (int).

+10
source share

It works great when using double backslashes and quotes like:

curl -i -H 'Accept: application / json' -H 'Content-Type: application / json' -X POST -d "{\" target \ ": \" 5142221345 \ ", \" source \ ": \" 432567890 \ ", \" messages \ ": [{\" format \ ": \" AMR \ ", \" data \ ": \" binarydata ... \ "}]}" http://10.4.4.11: 8089 / v1 / voice / add

0
source share

All Articles