(Medium) - Evolvable APIs
View original- current
This article is too short to summarise.
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
| // 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); |