Forum Discussion
Currently I'm building up system to test our REST Api's just using requests library in python.
This is success and more flexible than SOAP UI (for me)
can add libraries like this
only down side is it's functional testing only
let me know if need more info
NisHeraColin_McCraeAlexKaraskevin_kapell
Thanks for the reply.
I do have imported the required libraries earlier but I am getting a timeout error.
Is it ok if I ask for the code samples for how you are handling your request and response from the URLs ? As I am also working on REST I hope that will be a great help
Thanks All
- Colin_McCrae8 years agoCommunity Hero
Mine is VBScript ...
' Set up the POST Set json_object = CreateObject("MSXML2.ServerXMLHTTP") json_object.open "POST", <URL-OF-ENDPOINT>, False json_object.setRequestHeader "Content-Type", "application/json" ' Send the JSON json_object.send <JSON-DATA> ' Grab the reply code from the server reply = json_object.status
I use it as send only. (Hence always using "POST") The response is a simple response code. Which I normally expect to be a 200. And of course, it triggers some actions from the service it hits which are reflected on the website I run the tests against.
With a "GET" request, you get a JSON/XML blob in the response which you can parse.
<URL-OF-ENDPOINT> is the API endpoint you want to hit.
<JSON-DATA> is a string I build in code. It's only relevant to the application I'm testing obviously.
Pretty straightforward. More reading here: https://msdn.microsoft.com/en-us/library/ms766431(v=vs.85).aspx
- NisHera8 years agoValued Contributor
def getResponse(self,urlResource): # urlResource is the url for rest service try: headers = {'cmkey':self.sessionToken} # this is to send security token in my rest app response = requests.get(urlResource, headers=headers) if response.status_code!=requests.codes.ok: raise RestError("Request to GET failed with code := "+str(response.status_code)) except RestError as e: Log.Warning("Responce Error ",e.msg) finally: if response.text == "" : responsetx = response.status_code else: responsetx = response.text return responsetx
this is simplified function I wrote in general library class.
If it helps you..............
Related Content
- 2 years ago
Recent Discussions
- 4 days ago
- 4 days ago