How do I test APIs?

APIs can be tested in several ways and using different tools:

  • API Explorer - Feature within the Yale Developer Portal to try the Portal APIs.
  • Insomnia - Powerful browser extension or mac app to test APIs.
  • SOAPUI - Open-source web service testing application.
  • Web Browser - Test APIs directly in a browser if authentication for the API is none or API key based.
  • cURL - Test APIs from your local computer using command line tools.

API Explorer

The Yale Developer Portal includes the API Explorer tool for developers to try out the Portal APIs. 

NOTE:  Be sure you have created an Application within the developer portal that has access to the API you wish to try.  Review the Manage Applications and API Keys section within the Access to APIs how-to for additional information.

Within API Explorer:

  1. Select an API from the drop down menu.
  2. Select an App/API Key from the drop down menu.
  3. Click Edit and then select the Authentication Type “API Key” from the drop down menu.
  4. Click Save.
  5. Click “Expand Operations” on the right and add/edit parameters as desired.
  6. Click Submit.
  7. The API Explorer displays the query that it sent to the API and the response from the API.

NOTE:  Scroll to the bottom of the response to translate the query to another programming language by selecting the language from the drop down menu within “Code Samples.”

Image of API Explorer call in the Yale Developer Portal

Image of API Explorer response in the Yale Developer Portal

Insomnia

Easy to use, yet very powerful API testing tool.  More information and documentation can be found on the Insomnia website.

SOAPUI

SoapUI is an open-source web service testing application for service-oriented architectures and representational state transfers.  More information and documentation can be found on the SOAPUI website.

Web Browser

In the browser address bar, compose a query URL for the API to access.   The format of query URL is:

https:// hostname / api ? apikey=value

hostname - hostname listed for the API service

api - name of the API that is part of url provided in the API Documentation
? - only used in case of options (key=value pairs) separated with &
options (key=value pairs):
type=json - API data formats
key=0a1b3c4d5e6f7g8h9i0j1k2l3m412356 - API key provided after registering an application. 
 
Example constructed query:
https://gw.its.yale.edu/soa-gateway/buildings/feed?type=json&apikey=0a1b3c4d5e6f7g8h9i0j1k2l3m412345
*apikey in example is not a valid API key

cURL

If you are old-school like some of us terminal users, cURL is your friend. cURL is used in command line or scripts to transfer data. This tool will allow testing of APIs from your local computer. 
 
Apple Mac users, open Terminal window (Applications –> Utilities –> Terminal) and type in: curl
Windows users may need to download and install cURL.  Once installed open DOS Command Window and type in: curl
The following feedback should be returned: curl: try ‘curl –help’ or ‘curl –manual’ for more information
 
To use cURL please refer to the cURL manual for further details.
 
Example queries using cURL:
//get Building Room Data in XML
curl --include --request GET 'https://gw.its.yale.edu/soa-gateway/buildings/feed?method=getRoomData&apikey=0a1b3c4d5e6f7g8h9i0j1k2l3m412345'

//get Laundry Room Data in JSON
curl --include --request GET 'https://gw.its.yale.edu/soa-gateway/laundry/school?type=json&method=getRoomData&apikey=0a1b3c4d5e6f7g8h9i0j1k2l3m412345'
*apikey in example is not a valid API key