Search - MealsMadeEasy/Backend GitHub Wiki

/meals/search

As the name implies, this endpoint searches for and returns a list of meals that match given criteria. Parameters are passed to this endpoint as HTTP-encoded URL parameters. The following table shows the parameters available on this endpoint:

Parameter Name Required? Description
q Yes A query string to filter meals with. If this is empty, an empty list will be returned.
filters No A list of comma-separated filter IDs (e.g. low-fat,no-sugar,vegetarian). To obtain a list of valid filter IDs, see /meals/search/filters.

If a required parameter is missing, a 400 BAD REQUEST response code will be returned. If the search is successful, a list of Meal objects will be returned.

💰 Note: This endpoint reaches out to databases owned by third parties, which could cost money 💸. Because of this, make sure you debounce requests when the user is typing a query to avoid bombarding the server with unnecessary API calls.

/meals/search/filters

The list of available filters is dynamic, so it needs to be obtained from the server – ideally once per session. Unless the app is running in a production environment, it is inappropriate to cache this value. This endpoint returns a list of FilterGroups:

class FilterGroup(
        groupId: String /* A unique ID associated with this group. Currently unused, but may be useful for clients. */
        groupName: String /* A user-presentable string corresponding to the name of this filter group. */
        filters: List<Filter> /* A list of Filters that are in this group. Filters in this group will not appear in any other groups. */
        maximumActive: Int /* How many filters inside this group may be active at once. This value will be in the range of [1 and filters.size]. */
)

Each FilterGroup contains a list of Filter objects:

class Filter(
        id: String /* A unique ID associated with this filter that can be passed through the `filter` parameter to the search endpoint as described above. */
        name: String /* A user-presentable string corresponding to the name of this filter */
)

To allow filters to be separated and kept mutually-exclusive, they're grouped together with FilterGroups. Each FilterGroup then has a cap for how many filters inside the group may be active at a time when performing a search. If this number is exceeded, then the search will return a 400 BAD REQUEST response. Note that the number of groups and the size of the groups is arbitrary, so be sure to make client apps flexible enough to display these filters in a meaningful way.

⚠️ **GitHub.com Fallback** ⚠️