Testing APIs


There are many tools available to test different types of APIs e.g SOAPUI or POSTMAN etc. etc. However sometimes either you dont have a  GUI environment available or you just want to run a simple command to get the output from the API. In such cases the best tool to use is the curl command. Good thing about curl is that it is available in both Windows(10) and Linux. The syntax is quite simple:

 curl google.com


 

The default behavior is GET command for curl just like a browser. However using the command switches, curl can be used to make POST request as well and thats how you can test your APIs. 

curl -i -X POST "ENDPOINT URL"  --header Content-Type "<application/json or text/xml> etc."  --data "<PAYLOAD>"

Response from a SOAP based service:

-i/--include
              (HTTP) Include the HTTP-header in the output. The HTTP-header includes things like server-name, date of the document, HTTP-version and more

-X/--request <command>
              (HTTP)  Specifies  a  custom request method to use when communicating with the HTTP server.  The specified request will be used instead of the method otherwise used (which defaults to GET). Read the HTTP 1.1 specification  for  details  and  explanations. Common  additional  HTTP  requests include PUT and DELETE, but related technologies like WebDAV offers PROPFIND, COPY, MOVE and more.


Curl MAN page: https://linux.die.net/man/1/curl

Comments

Popular Posts