-
Notifications
You must be signed in to change notification settings - Fork 8
API Design
From Tyler's post on the discussion
Static Asset (GCS Bucket/CDN)
- Content: A feedstock_definitions.json file keyed by residue_type.
- Goal: Provides the heavy chemical metadata (Tier 2) without bloating the tiles or hitting the database.
Pros:
- Saves on storage costs
- Less infra to create/maintain
- Auditable changes to file
Cons:
- Relies on GitHub's availability for retrieval (tradeoff between GH and a Google Cloud Storage bucket's availability)
From Tyler's comment:
Backend API (FastAPI)
* Content: Tier 3 data above * Goal: Single-record retrieval. * Why: We need real-time data here. If `cost_per_ton` changes in Postgres, the frontend needs to reflect that immediately without waiting for a tile-gen pipeline to run.
- Query Parameters for API calls.
- The residue_type string in the Mapbox Tiles must strictly match the keys in the static JSON lookup. If the tile says "Almond" and the JSON says "Almond Prunings", the client-side join fails. We need a shared Enum definition here.
GET /api/feedstocks/usda/census?usda_crop={usda_crop}&geoid={geoid}¶meter={parameter}
-
usda_crop(str) -
geoid(str) -
parameter(str) -- parameter to retrieve fromusda_censustable
-
usda_crop(str) -- landIqusda_cropdata -
geoid(str) -
parameter(str) -- parameter requested fromusda_censustable -
value(float) -
unit(str) -
dimension(str) -
dimension_value(float) -
dimension_unit(str)
- 4xx:
CropNotFound-- whenusda_cropis not found in the table - 4xx:
ParameterNotFound-- whenparameteris not found for a particularusda_cropin the table
GET /api/feedstocks/usda/census?resource={resource}&geoid={geoid}¶meter={parameter}
-
resource(str) -- landIqresourcedata (API will need to convert tousda_cropviamain_crop) -
geoid(str) -
parameter(str) -- parameter to retrieve fromusda_censustable
-
resource(str) -- landIqresourcedata -
geoid(str) -
parameter(str) -- parameter requested fromusda_censustable -
value(float) -
unit(str) -
dimension(str) -
dimension_value(float) -
dimension_unit(str)
- 4xx:
ResourceNotFound-- whenresourceis not found in the table - 4xx:
ParameterNotFound-- whenparameteris not found for a particularresourcein the table
GET /api/feedstocks/usda/census?usda_crop={usda_crop}&geoid={geoid}
-
usda_crop(str) -
geoid(str)
-
usda_crop(str) -- landIqusda_cropdata -
geoid(str) -
data(list) -- list of parameters, values, and related data-
parameter(str) -- parameter requested fromusda_censustable -
value(float) -
unit(str) -
dimension(str) -
dimension_value(float) -
dimension_unit(str)
-
- 4xx:
CropNotFound-- whenusda_cropis not found in the table
GET /api/feedstocks/usda/census?resource={resource}&geoid={geoid}
-
resource(str) -- landIqresourcedata (API will need to convert tousda_cropviamain_crop) -
geoid(str)
-
resource(str) -- landIqresourcedata -
geoid(str) -
data(list) -- list of parameters, values, and related data-
parameter(str) -- parameter requested fromusda_censustable -
value(float) -
unit(str) -
dimension(str) -
dimension_value(float) -
dimension_unit(str)
-
- 4xx:
ResourceNotFound-- whenresourceis not found in the table
GET /api/feedstocks/usda/survey?usda_crop={usda_crop}&geoid={geoid}¶meter={parameter}
-
usda_crop(str) -
geoid(str) -
parameter(str) -- parameter to retrieve fromusda_censustable
-
usda_crop(str) -- landIqusda_cropdata -
geoid(str) -
parameter(str) -- parameter requested fromusda_censustable -
value(float) -
unit(str) -
dimension(str) -
dimension_value(float) -
dimension_unit(str)
- 4xx:
CropNotFound-- whenusda_cropis not found in the table - 4xx:
ParameterNotFound-- whenparameteris not found for a particularusda_cropin the table
GET /api/feedstocks/usda/survey?resource={resource}&geoid={geoid}¶meter={parameter}
-
resource(str) -- landIqresourcedata (API will need to convert tousda_cropviamain_crop) -
geoid(str) -
parameter(str) -- parameter to retrieve fromusda_censustable
-
resource(str) -- landIqresourcedata -
geoid(str) -
parameter(str) -- parameter requested fromusda_censustable -
value(float) -
unit(str) -
dimension(str) -
dimension_value(float) -
dimension_unit(str)
- 4xx:
ResourceNotFound-- whenresourceis not found in the table - 4xx:
ParameterNotFound-- whenparameteris not found for a particularresourcein the table
GET /api/feedstocks/usda/survey?usda_crop={usda_crop}&geoid={geoid}
-
usda_crop(str?) -
geoid(str)
-
usda_crop(str) -- landIqusda_cropdata -
geoid(str) -
data(list) -- list of parameters, values, and related data-
parameter(str) -- parameter requested fromusda_censustable -
value(float) -
unit(str) -
dimension(str) -
dimension_value(float) -
dimension_unit(str)
-
- 4xx:
CropNotFound-- whenusda_cropis not found in the table
GET /api/feedstocks/usda/survey?resource={resource}&geoid={geoid}
-
resource(str?) -- landIqresourcedata (API will need to convert tousda_cropviamain_crop) -
geoid(str)
-
resource(str) -- landIqresourcedata -
geoid(str) -
data(list) -- list of parameters, values, and related data-
parameter(str) -- parameter requested fromusda_censustable -
value(float) -
unit(str) -
dimension(str) -
dimension_value(float) -
dimension_unit(str)
-
- 4xx:
ResourceNotFound-- whenresourceis not found in the table
GET /api/feedstocks/availability?resource={resource}&geoid={geoid}
-
resource(str) -- landIqresourcedata -
geoid(str)
-
resource(str) -- landIqresourcedata -
geoid(str) -
from_month(int) -
to_month(int)
- 4xx:
ResourceNotFound-- whenresourceis not found in the table
GET /api/feedstocks/analysis?resource={resource}&geoid={geoid}¶meter={parameter}
-
resource(str) -- landIqresourcedata -
geoid(str) -
parameter(str) -- parameter to retrieve fromusda_censustable
-
resource(str) -- landIqresourcedata -
geoid(str) -
parameter(str) -- parameter requested fromusda_censustable -
value(float) -
unit(str)
- 4xx:
ResourceNotFound-- whenresourceis not found in the table - 4xx:
ParameterNotFound-- whenparameteris not found for a particularresourcein the table
GET /api/feedstocks/analysis?resource={resource}&geoid={geoid}
-
resource(str) -- landIqresourcedata -
geoid(str)
-
resource(str) -- landIqresourcedata -
geoid(str) -
data(list) -- list of parameters, values, and related data-
parameter(str) -- parameter requested fromusda_censustable -
value(float) -
unit(str)
-
- 4xx:
ResourceNotFound-- whenresourceis not found in the table