Last active
April 14, 2019 04:09
-
-
Save FagnerMartinsBrack/e37d8961472b98702514c4f45b574fe8 to your computer and use it in GitHub Desktop.
(Medium) - Evolvable APIs
This file contains 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
// The brains to fill the fields. This can use AI, etc. | |
const fillFields = (fields) => fields; | |
const run = async (method = 'GET', url = 'https://clinic.example.com/start-booking', fields) => { | |
const response = await fetch(url, { method: method, body: JSON.stringify(fields) }); | |
const parsedResponseBody = await response.json(); | |
const requiredFieldsAction = queryAction('required-fields', parsedResponseBody); | |
if (requiredFieldsAction) { | |
const filledFields = fillFields(requiredFieldsAction.attributes.fields); | |
return run(requiredFieldsAction.method, requiredFieldsAction.uri, filledFields); | |
} | |
return parsedResponseBody; | |
}; | |
// Initial trigger of the booking process | |
const result = await run(); | |
console.log('exit point', result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Question: shouldn't the recursive call to
run
pass thefilledFields
as the 3rd argument? I can't see howfilledFields
is used otherwise.