searchForFood & fetchSearchResult

Search the database of foods with a given search term.

searchForFood now returns PassioSearchResult and a list of search options. The PassioSearchResult represent a specific food item associated with the search term, while search options provide a list of possible suggested search terms connected to the input term.

Import the PassioSDK

import {
  PassioSDK,
  type FoodSearchResult,
} from '@passiolife/nutritionai-react-native-sdk-v3'

You can utilize the searchForFood API from the SDK to retrieve food records based on a search string. This API returns a PassioSearchResult object containing both results and alternatives.

The results property holds an array of food search results, while the alternatives property provides additional suggestions or alternative options if available.


  /**
   * Search the database of foods with a given search term.
   * @param searchQuery - The search term to match against food item names.
   * @returns A `Promise` resolving to an array of food item names.
   */
  searchForFood(searchQuery: string): Promise<PassioSearchResult | null>
  /**
   * Detail of search food with a given search result.
   * @param result - Provide `PassioSearchResult` object get `PassioFoodItem` detail.
   * @returns A `Promise` resolving to `PassioFoodItem` detail.
   */
  fetchSearchResult(result: FoodSearchResult): Promise<PassioFoodItem | null>

How to use it?

      try {
          // Fetch food results from the PassioSDK based on the query
          const searchFoods = await PassioSDK.searchForFood(query)
        } catch (error) {
          // Handle errors, e.g., network issues or API failures
        }

How to get PassioFoodItem using SerchFood Response?

   try {
          // Fetch food results from the PassioSDK based on the query
          const passioFoodItem = await PassioSDK.fetchSearchResult(foodSearchResult)
        } catch (error) {
          // Handle errors, e.g., network issues or API failures
        }

Last updated