Web and web services developers often need to send HTTP requests – whether for testing APIs, testing REST web services, or managing web sites.
XMLSpy now makes it easy to send and receive HTTP requests directly in the XML editor during development with a new HTTP Window and WADL Import Wizard.
Test HTTP Requests
The HTTP protocol defines how files (text, images, etc.) are transmitted over the Internet. Every web server runs a program (known as a daemon) that continuously waits for HTTP requests and handles each as it arrives.
For example, when you visit a website’s home page, your browser sends an HTTP command to the website’s web server that requests the download of the home page; the server’s HTTP daemon receives the request and sends the requested page. One significant property of HTTP bears noting: it is stateless, which means that each HTTP command is carried out independently, without any reference to previous or following commands, and this can make testing and debugging a challenge.
The HTTP testing window in XMLSpy guides you through the process of creating and sending an HTTP request to a web server. Then, you can receive, check, and troubleshoot the response.
A request is defined in the left-hand pane of the window and may consist of:
- The HTTP method of the request (GET, PUT, POST, etc.) and the target URL
- HTTP headers of the request
- Connection settings, e.g., time outs and security options
- For POST and PUT methods, the HTTP message body
Nine separate tabs in the HTTP window allow you to store and test multiple messages and switch between them as needed.
When the request is defined, press Send to send it to the web server and review the response in the right-hand pane, where you can review the body (shown above) and header info:
Importing a Request
You can also initiate a test by importing a request from a WADL (Web Application Description Language) file, which provides a machine-readable description of an HTTP-based application.
The XMLSpy HTTP window includes a WADL import wizard that walks you through opening a WADL file, selecting a request for testing, and modifying any editable parameters of the request.
Then it imports the request into the HTTP window so you can send it and review the response.
Debugging a REST API
Let’s take a look at a real-world example, using the HTTP window to test the response from a web API. The City of Chicago Data Portal is a publicly available REST API that provides interesting data about anything from building permits to numbers of cases of West Nile Virus in the city.
For this example, let’s delve into the traffic category and focus on a dataset of red light violations. I can enter the URL in the HTTP window to return the entire dataset, and ending the request with .xml or .json specifies the format of the returned data. I’ve chosen XML for this run, but of course XMLSpy has built-in tools for working with both formats. You can see the result returned by the HTTP window below.
We can review the data in the results pane or click Create New Document to open the document in XMLSpy text or grid view, where it’s easier to scroll through and spot check the data returned by the API.
With the data in a file we can even use XQuery to zero in further. Let’s take a look at camera locations with greater than 20 violations.
Now, let’s grab the data again, but this time in JSON format.
I’ve opened the file in text view above, but of course you can also view the JSON in grid view for a graphical representation.
The HTTP Window, along with built-in viewing and editing tools, make XMLSpy a great tool for testing and debugging APIs, Web services, and other HTTP applications.
Download a free trial of XMLSpy to try the HTTP window.