Quality Testing

Quality is delighting customers

Please suggest me how to automate REST POST api using python?

Please suggest me how to automate REST POST api using python?

Views: 7

Reply to This

Replies to This Discussion

Hi 
As per software testing company You can automate REST POST api by using python Request Module as shown in below code:


import requests

from requests_toolbelt.utils import dump

-----------------------------Json Header------------------------------
def header():       
             headers={
                         'Content-Type':'application/json',           
                           }       
              return headers

----------------------------------------Json Payload--------------------------

def payload(self):       
             rowjson = {           
                            "key1" : "value1",           
                            "key2" : "value2"           
                             }
            return rowjson 

--------------------------------------------------------------Sending Post Request---------------------

def send_Post_Request():        
           response=requests.post('Base Url'+endPoint,headers=header,json=payload
           data = dump.dump_all(response)
           print("\n\n--------------Request--------------------------\n",data.decode('utf-8'))       
           assert response.status_code==statusCode        jsonResponse=response.json() 
           return jsonResponse

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2020   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service