GithubHelp home page GithubHelp logo

marcortola / food-data-central Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 2.0 48 KB

PHP library for the FoodData Central FDC API (USDA nutrient database)

License: MIT License

PHP 100.00%
usda nutrient-database food-data fdc food-data-central usda-nutrient-database

food-data-central's Introduction

Community API client for the Food Data Central USDA nutrient database

Latest Version Build Status

Installation

  1. Install Composer
  2. Execute:
$ composer require marcortola/food-data-central

This wrapper doesn't bundle the HTTP client so you are free to use your preferred one. You can inject it in the FoodDataCentralClient constructor or let the wrapper discover it. If you don't know what I am talking about, the fast solution is to require these packages:

$ composer require php-http/curl-client nyholm/psr7 php-http/message

Usage

$foodDataCentralClient = FoodDataCentralClient::create('your_api_key');

// Find food by FDC ID.
$foodItem = $foodDataCentralClient->food()->food(781125);

// Find food nutrients. See the FoodItem interface for more nutrient finders.
$calcium = $foodDataCentralClient->food()->food(781125)->getCalcium();

Read the Food Data Central API documentation here.

License

Licensed under the MIT License. See License File for more information about it.

food-data-central's People

Contributors

marcortola avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

davgit dxdc

food-data-central's Issues

It doesn't work with PHP 7

I run composer require marcortola/food-data-central

and created my on file run.php like this:

<?php

require_once 'vendor/autoload.php';

$foodDataCentralClient = FoodDataCentralClient::create('MY_API');

// Find food by FDC ID.
$foodItem = $foodDataCentralClient->food()->food(781125);

// Find food nutrients. See the FoodItem interface for more nutrient finders.
$calcium = $foodDataCentralClient->food()->food(781125)->getCalcium();


 ?>

Command line execution of the file failed due to following error:

PHP Fatal error: Uncaught Error: Class 'FoodDataCentralClient' not found in /home/tomek/Dokumenty/food_data/run.php:5 Stack trace: #0 {main} thrown in /home/tomek/Dokumenty/food_data/run.php on line 5

Here is my php:
PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS )

Please help me to have this working. You did a great job with the API client anyway!

PHP 8 Support

Hey, just found out about your USDA API client SDK. Looks great!

Are you planning to support PHP "^8.0"?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.