USDA / USDA-APIs

Do you have feedback, ideas, or questions for USDA APIs? Use this repository's Issue Tracker to join the discussion.
www.usda.gov/developer
107 stars 16 forks source link

Any interest in GraphQL? #75

Open littlebunch opened 4 years ago

littlebunch commented 4 years ago

I've been working on a prototype GraphQL server using the Food Data Central datasets and am wondering if others have experience with or interest in the technology?

It certainly seems to address a number of problems I've encountered in developing public REST-API's -- namely, endpoint proliferation and results set granularity. For example, a developer needing to retrieve the value of sodium for a food or foods using the current REST API would need to download and parse upwards of >=20K bytes to find this one piece of information. Whereas using GraphQL, the exact information could be obtained with a simple query. Something like:

query { nutrientdata(fdcid:"352860",nutids:[307]){ value }}

will return something like: { "data": { "nutrientdata": [ { "value": 1733 } ] } }

It's a bit surprising how easy it is to develop a server by bolting it onto an existing REST API library. I'm also bowled over by it's self-documenting nature, i.e. because it's schema driven.

richpowell commented 3 years ago

apparently its available. but .. a bit more documentation would help.. anyways you can discover the schema

curl \
-X POST \
-H "Content-Type: application/json" \
--data '{ "query": "  {__schema { types {name}}}" }' \
https://api.ers.usda.gov/data/arms/graphql?api_key="your api key goes here"
littlebunch commented 3 years ago

This is cool! I did not know ERS has a graphql interface. Could have seriously used it a few years back.

FWIW, the latest instance of my Branded Food Products graphql prototype, which is not a USDA sponsored site, is at https://rs.littlebunch.com.