Mastering Ajax, part 9th: Using the Google Ajax Search API

Source: Internet
Author: User
Tags ibm developerworks advantage

Using public APIs in asynchronous applications

Introduction: Making an asynchronous request does not mean interacting with your own server-side program only. You can also communicate with some public APIs, such as Google or Amazon, to add more functionality to your WEB application than your own scripts and server-side programs can provide. In this article, Brett McLaughlin teaches you how to make requests and receive responses to public APIs, such as Google-supplied APIs.

So far, this series is concerned only with client Web pages making requests to server-side scripts and programs. This is how about 80% to 90% of Ajax applications (asynchronous WEB applications using XMLHttpRequest objects) work. However, there are serious limitations to this approach: you will be limited by your talents and programming skills, and, if not, at least be limited by the ingenuity and programming skills of the programmers on the corporate team.

Sometimes you do want to implement some functionality, but you don't have the technical knowledge you need to achieve that goal, and you can almost always experience this. Maybe you don't know some syntax, maybe you don't know how to find the right algorithm. There are times when you may not have the data or resources (either human or data) that you need to meet your needs. In these cases, you might think, "Alas, if only I could use other people's Code!" "This article is to solve this problem.

Open source Scripts and programs

Before discussing the actual content of this article (using a common API in a WEB application), it is necessary to say something about open source scripts and programs. In plain terms, open source is a term used to describe code that can be used and reused in your own application to some extent free of charge. See resources for RELATED links. In short, you can get open source written by someone else and put it into your own environment without having to pay for it and not be limited by (many).

If you use open source, there are times when you need to add additional documentation to your application or give feedback to your community about changes you make to open source programs or scripts. No matter how you use this program, the end result is that you can use a piece of code that you don't have to write yourself, or that you can't write without a lot of help and resources, and you don't have the resources on hand. Projects like Apache make it easy to take advantage of other people's work-don't worry, they want you to use their work!

Online articles and Tutorials

It would be foolish to publish an article on IBM DeveloperWorks without mentioning a great deal of reference materials, such as articles, tutorials, and white papers on the Internet. There are hundreds of thousands of textbooks on the web, and you may find nearly waking about Ajax--in this series, I've published nearly 10 articles! Most of these articles have code, examples, downloads, and various other types of resources available.

If you don't have the ability to write a server-side program or script to use, or if you can't find the open source program or script you want, you can open the Google Web site and try to enter a basic description of what you're looking for. Then perform the same action on the DeveloperWorks Web site. You can often find the code you need, even the entire script, and there are helpful comments and descriptions of how it works.

Using the public API

Many times, you will experience a technical problem. You don't need help to write a script or a piece of code, but you don't have the data or resources on hand. In these cases, even with tutorials or open source scripts, more needs to be made. For example, consider adding a search engine to a Web page. The premise is that you already have the data to search for--but what if you want to search for data outside your company or organization?

If it is not because of technical reasons, but because the data is limited, then a public API may help you solve the problem. The public API allows you to use programs on other people's servers and use other people's data. Typically, the API itself defines only how to interact with the program. For example, a public API for a Google search engine can send a search request, but it is actually Google's code that searches Google's data and returns the results to your program. Not only can you take advantage of other people's skills in writing these programs, but you can also take advantage of data that is far more than your own company can support.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.