Using Google Search API in ASP.Net Web API


This article explains you how to use the Google Search API in the ASP.NET Web API. Here we use a variable "sitesearch" that handles the Google Search engine. If we have the null value of the variable "sitesearch" then it searches the entire web and if we mention any site as the value of "sitesearch" then it searches only that site.

Google API

  • The Google API service is a beta web program that allows programmers to easily search and manage the information on the web.
  • The Google API is used by developers and researchers only for finding information but it cannot be use as a resource in any application.
  • It uses the SOAP (Simple Object Access Protocol) and WSDL (Web Services Description Language) to provide the interface between the program's user and the Google API.
  • Different programming environment  that are suitable for the Google API that are Visual Studio.NET, Java and so on.
  • Developers and the researcher use the Google API to examine the request; it can be more than 3 billion web pages that are allowed by the Google API.

Let us see the procedure to use the Google API in the Web API.

  1. First we create a Web API Application.
    • Start Visual Studio 2012.
    • From the start window Select "Installed" -> "Visual C#" -> "Web".
    • Select "ASP.NET MVC4 Web Application" and click the "OK" button.

    • From the "MVC4 Project" window select "Web API".


    • Click the "OK" button.
  1. Now we add some code in the "Index.cshtml" file for using the Google API. This file exists:
    • In the "Solution Explorer".
    • Expand the "Home" folder.
    • Then select the "index.cshtml" file.
    • Add this code:
      1. <!DOCTYPE>  
      2. <html xmlns="">   
      3. <head>  
      4.     <title>c-sharpcorner</title>  
      5. </head>  
      6. <body>  
      7.     <form method="get" action="">  
      8.     <input type="text" name="q" size="40" maxlength="255" value="" />  
      9.     <input type="submit" value="Search" />  
      10.    <br /> <input type="radio" name="sitesearch" value="" />  
      11.     Search on Web  
      12.     <input type="radio" name="sitesearch" value="" checked />  
      13.     Search from c-sharpcorner<br />  
      14.           <input type="radio" name="sitesearch" value="" checked />  
      15. search on MSDN  
      16.     </form>  
      17. </body>  
      18. </html>
      In the code above we have three radio buttons and three "sitesearch" variables. From which the first variable has a null value, in other words when we search for soomething it will search the entire web, the second has the site "" if we choose this radio button and find the information then it will search only in the site "". The last one has the value ""; when it is chosen only the "MSDN" site is searched for the information.
  1. Now to execute the application. Press "F5" and check that it is working. The output will be as in the following:


    If we choose "Search on Web" then the output will be:

    If we choose the site "" then the output will be:


    If we choose the site "" then the output will be:


Similar Articles