Across the web, users make extensive use of sites that perform specific tasks. People book their travel, for example, at Travelocity, buy books at Amazon, perform online banking at Bank of America, and order pizza at Domino’s. These sites offer services to the user, but the sites are webpages, not web services. A web service is program code that resides on the web and performs a specific task that other programs, not people, use. Examples of tasks that a web service might perform include the following:
Return the weather conditions for a specific zip code
Return real-time traffic conditions for a road or highway
Return a stock price for a specific company
Return driving directions to a specific location
Return the country associated with an IP address
And much more
Programmers use web services within the programs they create to perform specific processing. To use a web service, a program exchanges messages across the Internet with the web service that resides on a remote server. The program may pass parameter values to the service, such as a stock symbol of the company for which the program wants the stock price or the zip code of the area for which the program wants weather conditions. When a program calls a web service, the program will normally send its message to the web service via a function call and then wait, as shown in FIGURE 11.2, for the web service to return its result.
Programmers often refer to web services as microservices or APIs, which stands for “application program interface (API).” When you hear the term “API”, think “web service.”
When programmers create applications, they often need the program to perform tasks that involve another company:
Determining the shipping rate to send a package via UPS or FedEx
Determining if a company has a particular product in inventory, and if so, the quantity available
Performing credit card processing
Placing an order for a product
To help programmers perform such tasks, many companies provide web services. FedEx and UPS, for example, provide web services that programs can use to fully integrate each company’s shipping and tracking capabilities. Amazon provides web services that programmers can use to integrate product searching and purchasing into their applications. Google provides web services that programs can use to access the site’s search-engine capabilities.