Skip to content

API Endpoints

Dylan Havelock edited this page Feb 16, 2020 · 9 revisions

/nutri/fooditem/

/nutri/meal/

/nutri/mealentry/

/nutri/daily/

/nutri/fooditem/

POST

Creates a new FoodItem object
// Request
{
    "name": "oatmeal",
    "protein": 9,
    "fat": 12,
    "carb":36
}

// Response
{
    "fooditem": {
        "id": 4,
        "name": "oatmeal",
        "protein": 9,
        "carb": 36,
        "fat": 12,
        "user": 1
    }
}

GET

Gets all FoodItems in the database
// Request
{}

// Response
{
    "fooditems": [
        {
            "id": 1,
            "name": "Banana",
            "protein": 20,
            "carb": 20,
            "fat": 20,
            "user": null
        },
        {
            "id": 2,
            "name": "Apple",
            "protein": 10,
            "carb": 10,
            "fat": 10,
            "user": null
        },
        {
            "id": 3,
            "name": "cake",
            "protein": 20,
            "carb": 20,
            "fat": 20,
            "user": null
        },
        {
            "id": 4,
            "name": "oatmeal",
            "protein": 9,
            "carb": 36,
            "fat": 12,
            "user": 1
        }
    ]
}

/nutri/meal/

GET

Gets a list of the User's Meals

// Request
{}

// Response
{
    "meals": [
        {
            "id": 1,
            "name": "smoothie",
            "protein": 50,
            "carb": 50,
            "fat": 50,
            "user": 1,
            "fooditems": [
                {
                    "id": 1,
                    "name": "Banana",
                    "protein": 20,
                    "carb": 20,
                    "fat": 20,
                    "user": 1
                },
                {
                    "id": 2,
                    "name": "Apple",
                    "protein": 10,
                    "carb": 10,
                    "fat": 10,
                    "user": 1
                },
                {
                    "id": 3,
                    "name": "kiwi",
                    "protein": 20,
                    "carb": 20,
                    "fat": 20,
                    "user": 1
                }
            ],
        },
        {
            "id": 2,
            "name": "snack",
            "protein": 10,
            "carb": 30,
            "fat": 20,
            "user": 1,
            "fooditems": [
                {
                    "id": 3,
                    "name": "kiwi",
                    "protein": 20,
                    "carb": 20,
                    "fat": 20,
                    "user": 1
                }
            ]
        },
    ]
}

POST

Creates a new Meal object

// Request
{
    "fooditems": [1, 2, 3],
    "name": "smoothie"
}

// Response
{
    "meal": {
        "id": 5,
        "name": "smoothie",
        "protein": 21,
        "carb": 52,
        "fat": 7,
        "user": null,
        "fooditems": [
            1,
            2,
            3
        ]
    }
}

or, alternatively supply macronutrients and no FoodItem IDs

// Request
{
    "name": "meal without food items",
    "protein": 10,
    "fat": 20,
    "carb": 30
}

// Response
{
    "meal": {
        "id": 6,
        "name": "meal without food items",
        "protein": 10,
        "carb": 30,
        "fat": 20,
        "user": 1,
        "fooditems": []
    }
}

/nutri/mealentry/

POST

Creates a meal entry

// Request
{
    "meal": 1,
    "timestamp": "2020-02-04T03:02:24.397383Z" // optional
}

// Response
{
    "mealentry": {
        "id": 1,
        "timestamp": "2020-02-04T03:02:24.397383Z",
        "user": 1,
        "meal": 1
    }
}

/nutri/daily/

GET

Gets the current macronutrient totals that have been entered for that day

// Request
{}

// Response
{
    "num_meals": 2,
    "protein": 62,
    "carb": 81,
    "fat": 23
}

Clone this wiki locally