The FoodData Central API provides REST access to FoodData Central (FDC). It is intended primarily to assist application developers wishing to incorporate nutrient data into their applications or websites. To take full advantage of the API, developers should familiarize themselves with the database by reading the database documentation available via links on Data Type Documentation. This documentation provides the detailed definitions and descriptions needed to understand the data elements referenced in the API documentation. Additional details about the API including rate limits, access, and licensing are available on the FDC website
This C# SDK is automatically generated by the Swagger Codegen project:
- API version: 1.0.1
- SDK version: 1.0.0
- Build package: io.swagger.codegen.v3.generators.dotnet.CSharpClientCodegen For more information, please visit https://nal.altarama.com/reft100.aspx?key=FoodData
- .NET 4.0 or later
- Windows Phone 7.1 (Mango)
- RestSharp - 105.1.0 or later
- Json.NET - 7.0.0 or later
- JsonSubTypes - 1.2.0 or later
The DLLs included in the package may not be the latest version. We recommend using NuGet to obtain the latest version of the packages:
Install-Package RestSharp
Install-Package Newtonsoft.Json
Install-Package JsonSubTypes
NOTE: RestSharp versions greater than 105.1.0 have a bug which causes file uploads to fail. See RestSharp#742
Run the following command to generate the DLL
- [Mac/Linux]
/bin/sh build.sh
- [Windows]
build.bat
Then include the DLL (under the bin
folder) in the C# project, and use the namespaces:
using IO.FoodDataCentralSDK.Api;
using IO.FoodDataCentralSDK.Client;
using IO.FoodDataCentralSDK.Model;
A .nuspec
is included with the project. You can follow the Nuget quickstart to create and publish packages.
This .nuspec
uses placeholders from the .csproj
, so build the .csproj
directly:
nuget pack -Build -OutputDirectory out IO.FoodDataCentralSDK.csproj
Then, publish to a local feed or other host and consume the new package via Nuget as usual.
using System;
using System.Diagnostics;
using IO.FoodDataCentralSDK.Api;
using IO.FoodDataCentralSDK.Client;
using IO.FoodDataCentralSDK.Model;
namespace Example
{
public class Example
{
public void main()
{
// Configure API key authorization: ApiKeyAuth
Configuration.Default.ApiKey.Add("api_key", "YOUR_API_KEY");
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// Configuration.Default.ApiKeyPrefix.Add("api_key", "Bearer");
var apiInstance = new FDCApi();
var fdcId = fdcId_example; // string | FDC id of the food to retrieve
var format = format_example; // string | Optional. 'abridged' for an abridged set of elements, 'full' for all elements (default). (optional)
var nutrients = new List<int?>(); // List<int?> | Optional. List of up to 25 nutrient numbers. Only the nutrient information for the specified nutrients will be returned. Should be comma separated list (e.g. nutrients=203,204) or repeating parameters (e.g. nutrients=203&nutrients=204). If a food does not have any matching nutrients, the food will be returned with an empty foodNutrients element. (optional)
try
{
// Fetches details for one food item by FDC ID
InlineResponse200 result = apiInstance.GetFood(fdcId, format, nutrients);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling FDCApi.GetFood: " + e.Message );
}
}
}
}
All URIs are relative to https://api.nal.usda.gov/fdc
Class | Method | HTTP request | Description |
---|---|---|---|
FDCApi | GetFood | GET /v1/food/{fdcId} | Fetches details for one food item by FDC ID |
FDCApi | GetFoods | GET /v1/foods | Fetches details for multiple food items using input FDC IDs |
FDCApi | GetFoodsList | GET /v1/foods/list | Returns a paged list of foods, in the 'abridged' format |
FDCApi | GetFoodsSearch | GET /v1/foods/search | Returns a list of foods that matched search (query) keywords |
FDCApi | GetJsonSpec | GET /v1/json-spec | Returns this documentation in JSON format |
FDCApi | GetYamlSpec | GET /v1/yaml-spec | Returns this documentation in JSON format |
FDCApi | PostFoods | POST /v1/foods | Fetches details for multiple food items using input FDC IDs |
FDCApi | PostFoodsList | POST /v1/foods/list | Returns a paged list of foods, in the 'abridged' format |
FDCApi | PostFoodsSearch | POST /v1/foods/search | Returns a list of foods that matched search (query) keywords |
- Model.AbridgedFoodItem
- Model.AbridgedFoodNutrient
- Model.BrandedFoodItem
- Model.BrandedFoodItemLabelNutrients
- Model.BrandedFoodItemLabelNutrientsCalcium
- Model.BrandedFoodItemLabelNutrientsCalories
- Model.BrandedFoodItemLabelNutrientsCarbohydrates
- Model.BrandedFoodItemLabelNutrientsFat
- Model.BrandedFoodItemLabelNutrientsFiber
- Model.BrandedFoodItemLabelNutrientsIron
- Model.BrandedFoodItemLabelNutrientsPotassium
- Model.BrandedFoodItemLabelNutrientsProtein
- Model.BrandedFoodItemLabelNutrientsSaturatedFat
- Model.BrandedFoodItemLabelNutrientsSugars
- Model.BrandedFoodItemLabelNutrientsTransFat
- Model.FoodAttribute
- Model.FoodAttributeFoodAttributeType
- Model.FoodCategory
- Model.FoodComponent
- Model.FoodListCriteria
- Model.FoodNutrient
- Model.FoodNutrientDerivation
- Model.FoodNutrientSource
- Model.FoodPortion
- Model.FoodSearchCriteria
- Model.FoodUpdateLog
- Model.FoodsCriteria
- Model.FoundationFoodItem
- Model.InlineResponse200
- Model.InputFoodFoundation
- Model.InputFoodSurvey
- Model.MeasureUnit
- Model.Nutrient
- Model.NutrientAcquisitionDetails
- Model.NutrientAnalysisDetails
- Model.NutrientConversionFactors
- Model.RetentionFactor
- Model.SRLegacyFoodItem
- Model.SampleFoodItem
- Model.SearchResult
- Model.SearchResultFood
- Model.SurveyFoodItem
- Model.WweiaFoodCategory
- Type: API key
- API key parameter name: api_key
- Location: URL query string
click on pack.bat
cd .\src\IO.FoodDataCentralSDK
..\..\nuget pack -Build -OutputDirectory out FoodDataCentralSDK.csproj
add your api key in INSERT_Nuget_API_Key_Here and create and run publish.bat note that this file is not checked in and is ignored. be sure to change the version by clicking on the project and opening properties and changing the assembly info. then update the version below as x.x.x.nupkg
..\..\nuget push out\FoodDataCentralSDK.1.0.2.nupkg <INSERT_Nuget_API_Key_Here> -Source https://api.nuget.org/v3/index.json