zbowl/food-data-central-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

zbowl/food-data-central-api

Composer 安装命令:

composer require zbowl/food-data-central-api

包简介

Integration for Food Data Central API

README 文档

README

This is a Laravel wrapper for the Food Data Central API. It is a work in progress.

Config

Publish the configuration.

php artisan vendor:publish --provider="zbowl\FoodDataCentral\FoodDataCentralServiceProvider" --tag="config"

Add environment variables to your .env.

FOOD_DATA_CENTRAL_BASE_URI=
FOOD_DATA_CENTRAL_API_VERSION=
FOOD_DATA_CENTRAL_API_KEY=
FOOD_DATA_CENTRAL_API_TIMEOUT=
FOOD_DATA_CENTRAL_API_RETRY_TIMES=
FOOD_DATA_CENTRAL_API_RETRY_DELAY=

They will be used in the food-data-central config.

/*
     * The base url used to for Food Data Central.
     *
     */
    'baseUri' => env('FOOD_DATA_CENTRAL_API_URI', 'https://api.nal.usda.gov/fdc'),

    /*
     * The API version provided by Food Data Central.
     *
     */
    'apiVersion' => env('FOOD_DATA_CENTRAL_API_VERSION', 'v1'),
    /*
     * The API Key provided by Food Data Central.
     * https://api.data.gov/signup/
     * https://fdc.nal.usda.gov/api-key-signup.html
     *
     */
    'apiKey' => env('FOOD_DATA_CENTRAL_API_KEY', null),
    /*
     * How long before the connection timeout.
     * Default is 10
     */
    'timeout' => env('FOOD_DATA_CENTRAL_API_TIMEOUT', 10),
    /*
     * The number of times a retry is allowed.
     * This is not used by default.
     */
    'retryTimes' => env('FOOD_DATA_CENTRAL_API_RETRY_TIMES', null),
    /*
     * The time between retry attempts in milliseconds.
     * This is not used by default.
     */
    'retryMilliseconds' => env('FOOD_DATA_CENTRAL_API_RETRY_DELAY', null),

    /*
     * The path to the migrations.
     */
    'includeMigrations' => env('FOOD_DATA_CENTRAL_API_INCLUDE_MIGRATIONS', false),

Usage

use zbowl\FoodDataCentralApi\Facade\FoodDataCentral;

public function search(Request $request)
{
    $request->validate([
        'query' => 'required|string',
    ]);
    $searchTerm = $request->searchInput;
    
    $foodDataCentral = new FoodDataCentral();
    $results = $foodDataCentral::getFoodsSearch($searchTerm);
    
    return view('search', compact('results'));
}

{
    $foodDataCentral = FoodDataCentral::class;
    $results = $foodDataCentral::getFoodsSearch('apple');
    return $results;
}

Resources

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固