Skip to content

Instantly share code, notes, and snippets.

@FagnerMartinsBrack
Last active April 14, 2019 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save FagnerMartinsBrack/e37d8961472b98702514c4f45b574fe8 to your computer and use it in GitHub Desktop.
Save FagnerMartinsBrack/e37d8961472b98702514c4f45b574fe8 to your computer and use it in GitHub Desktop.
(Medium) - Evolvable APIs
// 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);
@tzachz
Copy link

tzachz commented Feb 25, 2019

Question: shouldn't the recursive call to run pass the filledFields as the 3rd argument? I can't see how filledFields is used otherwise.

@giangnn
Copy link

giangnn commented Mar 8, 2019

Agree with @tzachz. I visited this page to post the same question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment