This API allows users to search for any information over the web. This replicates a typical search engine experience, where users can search for any information they need.

Using the Basic Web Search API

The following examples demonstrate how to interact with the Basic Web Search API using both multiple coding platform.

Request Sample

The below code snippet:

  • Sends an HTTP GET request to the https://apis.datura.ai/web API to retrieve the latest news related to AI.

  • The script defines the API endpoint and sets query parameters, including a search query for “latest news on AI” the number of results to fetch (num: 10), and the starting index (start: 0).

  • Additionally, it specifies headers, including an Authorization key (which needs to be replaced with a valid API key) and a Content-Type set to application/json.

  • The request is then sent using requests.get, but there is a mistake in the method call—the “GET” string should not be included, as requests.get(url, params=params, headers=headers) is the correct syntax.

  • Finally, the script prints the response content, displaying the retrieved news data.

    import requests

    url = "https://apis.datura.ai/web"

    params =  {
      "query": "latest news on AI",
      "num": 10,
      "start": 0
    }
    headers = {
        "Authorization": "<your-api-key>",
        "Content-Type": "application/json"
    }

    response = requests.get("GET", url, params=params, headers=headers)

    print(response.text)

Parameters

Required

  • url: The endpoint for the Basic Web Search API.

  • payload / query

    • query: The search query string, e.g., ‘latest news on AI’.

Optional

  • num: Count of results to get, e.g., 10
  • start: How many results to skip (used for pagination with num), e.g., 0

Response Sample

Based on the above code, here is how the response is retrieve as JSON. Each coding language has its own way of retrieving data from the below JSON.

    PENDING RESPONSE

Test API

To experiment with the Basic Web Search API and see it in action, visit the Basic Web Search API.