Last active
May 7, 2020 00:51
-
-
Save neptunius/4d0e5b1a1ffd319335d6235ed638c578 to your computer and use it in GitHub Desktop.
API Response JSON Format – Ben Lafferty's BK Tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // PROTOTYPE | |
| // API route format: api.ben.com/<query:str>/<distance:int> | |
| // Request example: api.ben.com/hello/2 | |
| // Response JSON: | |
| { | |
| "exact": ["hello"], | |
| "close": ["cell", "cello", "helio", "helix", "hell", ...] | |
| } | |
| // RECOMMENDED – API standards: https://github.com/WhiteHouse/api-standards | |
| // API route format: api.ben.com/words?query=<str>&distance=<int>&limit=<int> | |
| // Request example: api.ben.com/words?query=hello&distance=2&limit=50 | |
| // Response JSON: | |
| { | |
| "query": "hello", | |
| "distance": 2, | |
| "limit": 50, | |
| "count": 27, | |
| "results": [ | |
| { "distance": 0, "words": ["hello"] }, | |
| { "distance": 1, "words": ["cello", "helio", "hell", ...] }, | |
| { "distance": 2, "words": ["cell", "helix", ...] } | |
| ] | |
| } | |
| // FUTURE IDEA – If you download and parse a corpus of word frequency counts (like Google Ngrams) | |
| // Query parameter: "order" can be specified as "lexicographical" (like before) or "frequency" | |
| // API route format: api.ben.com/words?query=<str>&distance=<int>&limit=<int>&order=<frequency|lexicographical> | |
| // Request example: api.ben.com/words?query=hello&distance=2&limit=50&order=frequency | |
| // Response JSON: | |
| { | |
| "query": "hello", | |
| "distance": 2, | |
| "limit": 50, | |
| "count": 27, | |
| "order": "frequency", | |
| "results": [ | |
| { "word": "hello", "distance": 0, "frequency": 999 }, | |
| { "word": "hell", "distance": 1, "frequency": 666 }, | |
| { "word": "cell", "distance": 2, "frequency": 555 }, | |
| { "word": "cello", "distance": 1, "frequency": 333 }, | |
| { "word": "helix", "distance": 2, "frequency": 222 }, | |
| ... | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment