Git Product home page Git Product logo

fs-api's Introduction

fs-api

The fs-api provides a REST API for the FatSecret service. See the architecture documentation for an overview.

Usage

In order to use fs-api one needs to register to obtain OAuth 1.0 Credentials. These Consumer Key and Consumer Secret have to be provided to fs-api as environment variables. Assuming a bash like shell:

$ export FATSECRET_CONSUMER_KEY=...
$ export FATSECRET_CONSUMER_SECRET=...

After that the application can be started from the top-level application directory as

$ mvnw spring-boot:run

Alternativly you can split the tasks of building the (fat) JAR file from executing it:

$ mvnw package
$ java -jar target/fs-api-0.0.1-SNAPSHOT.jar

For tests it is helpful to have a JSON pretty printer like jq available:

$ curl --silent http://localhost:8080/api/v1/food?q=avocado | jq
[
  {
    "name": "Avocado",
    "url": "https://www.fatsecret.com/calories-nutrition/calavo/avocado",
    "type": "Brand",
    "id": 66325,
    "description": "Per 1/2 medium avocado - Calories: 130kcal | Fat: 12.00g | Carbs: 6.00g | Protein: 1.00g",
    "brandName": null
  },
  {
    "name": "Avocados",
    "url": "https://www.fatsecret.com/calories-nutrition/usda/avocados",
    "type": "Generic",
    "id": 35752,
    "description": "Per 100g - Calories: 160kcal | Fat: 14.66g | Carbs: 8.53g | Protein: 2.00g",
    "brandName": null
  },
  {
    "name": "Hass Avocado",
    "url": "https://www.fatsecret.com/calories-nutrition/trader-joes/hass-avocado",
    "type": "Brand",
    "id": 270988,
    "description": "Per 1/5 medium  - Calories: 50kcal | Fat: 4.50g | Carbs: 3.00g | Protein: 0.00g",
    "brandName": null
  },
  ...
]
$ curl --silent http://localhost:8080/api/v1/food/35752 | jq
{
  "name": "Avocados",
  "url": "https://www.fatsecret.com/calories-nutrition/usda/avocados",
  "type": "Generic",
  "id": 35752,
  "description": null,
  "brandName": "",
  "servings": [
    {
      "servingId": 32965,
      "servingDescription": "1 cup cubed",
      "servingUrl": "https://www.fatsecret.com/calories-nutrition/usda/avocados?portionid=32965&portionamount=1.000",
      "metricServingAmount": 150,
      "metricServingUnit": "g",
      "numberOfUnits": 1,
      "measurementDescription": "cup, cubes",
      "calories": 240,
      "carbohydrate": 12.8,
      "protein": 3,
      "fat": 21.99,
      "saturatedFat": 3.189,
      "polyunsaturatedFat": 2.724,
      "monounsaturatedFat": 14.698,
      "transFat": null,
      "cholesterol": 0,
      "sodium": 10,
      "potassium": 728,
      "fiber": 10,
      "sugar": 0.99,
      "vitaminA": 4,
      "vitaminC": 25,
      "calcium": 2,
      "iron": 5
    },
    ...
  ]
}

Deployment

The API can be packaged as a Docker image with

$ mvnw install dockerfile:build

The resulting image can be run with

$ docker run -d --rm -p 8080:8080 \
    -e FATSECRET_CLIENT_ID -e FATSECRET_CLIENT_SECRET \
    rstub/fs-api

If the docker container is run some other way (docker-compose, kubernetes, ...) the port-forwarding and environment variables have to be defined in the run-time configuration.

fs-api's People

Watchers

 avatar  avatar

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.