ferrisoxide / brocade.io

Open GTIN / barcode & product database
https://www.brocade.io
GNU Affero General Public License v3.0
111 stars 6 forks source link

API Consumption Helpful Information #37

Open MrRedBeard opened 4 years ago

MrRedBeard commented 4 years ago

Is this accurate? I kept looping through records to try understand the API behavior and data structure/types.

This information might be helpful for those consuming the API.

Header Pagination Info

Header - links - First Header

https://www.brocade.io/api/items?page=20&query=peanut+butter; rel="last", https://www.brocade.io/api/items?page=2&query=peanut+butter; rel="next"

Header - links - Following Headers include the previous and

https://www.brocade.io/api/items?page=1&query=peanut+butter; rel="first", https://www.brocade.io/api/items?page=1&query=peanut+butter; rel="prev",

Header - per-page & total

per-page - Results per page = 100 total - Total number records = 1912 total / per-page = Total Pages 19.12 rounded up = 20. Total is also found in Header - links last

Data Types

**Key                   DataType**
ProductID               int
gtin14                  string
brand_name              string
name                    string
fat                 string
size                    string
fiber                   string
sodium                  string
sugars                  string
protein                 string
calories                string
potassium               string
cholesterol             string
ingredients             string
carbohydrate                string
fat_calories                string
serving_size                string
saturated_fat               string
trans_fat               string
monounsaturated_fat         string
polyunsaturated_fat         string
servings_per_container          string
pages                   string
author                  string
format                  string
publisher               string
alcohol_by_volume           double
alcohol_by_weight           double
volume_fluid_ounce          double
volume_ml               double
weight_g                double
weight_ounce                double
unit_count              double

Example JS Class of Data Structure

class clsProducts
{
    constructor()
    {
        this.gtin14 = '';
        this.brand_name = '';
        this.name = '';
        this.fat = '';
        this.size = '';
        this.fiber = '';
        this.sodium = '';
        this.sugars = '';
        this.protein = '';
        this.calories = '';
        this.potassium = '';
        this.cholesterol = '';
        this.ingredients = '';
        this.carbohydrate = '';
        this.fat_calories = '';
        this.serving_size = '';
        this.saturated_fat = '';
        this.trans_fat = '';
        this.monounsaturated_fat = '';
        this.polyunsaturated_fat = '';
        this.servings_per_container = '';
        this.pages = '';
        this.author = '';
        this.format = '';
        this.publisher = '';
        this.alcohol_by_volume = null; //Double
        this.alcohol_by_weight = null; //Double
        this.volume_fluid_ounce = null; //Double
        this.volume_ml = null; //Double
        this.weight_g = null; //Double
        this.weight_ounce = null; //Double
        this.unit_count = null; //Double
    }
}

Example c# Class of Data Structure

public class Products
    {
        public string gtin14 { get; set; }
        public string brand_name { get; set; }
        public string name { get; set; }
        public string fat { get; set; }
        public string size { get; set; }
        public string fiber { get; set; }
        public string sodium { get; set; }
        public string sugars { get; set; }
        public string protein { get; set; }
        public string calories { get; set; }
        public string potassium { get; set; }
        public string cholesterol { get; set; }
        public string ingredients { get; set; }
        public string carbohydrate { get; set; }
        public string fat_calories { get; set; }
        public string serving_size { get; set; }
        public string saturated_fat { get; set; }
        public string trans_fat { get; set; }
        public string monounsaturated_fat { get; set; }
        public string polyunsaturated_fat { get; set; }
        public string servings_per_container { get; set; }
        public string pages { get; set; }
        public string author { get; set; }
        public string format { get; set; }
        public string publisher { get; set; }
        public double? alcohol_by_volume { get; set; }
        public double? alcohol_by_weight { get; set; }
        public double? volume_fluid_ounce { get; set; }
        public double? volume_ml { get; set; }
        public double? weight_g { get; set; }
        public double? weight_ounce { get; set; }
        public double? unit_count { get; set; }
    }
ferrisoxide commented 3 years ago

Hey @MrRedBeard

Awesome. I'll update the documentation as soon as I get a chance. Thank you for that.

The rest looks right, though just be forewarned that all the attributes other than id, gtin14, brand_name and name are arbitrary, i.e. you can add any key/value pair you want.

I'm still thinking through the notion of Property Sets (#22). Adding type info to the valid data makes sense, in which case declaring double/int will work. Right now properties are just stored as strings, inside a JSON field.