invent icon indicating copy to clipboard operation
invent copied to clipboard

It should be possible to make HTTP requests to and endpoint and process the result

Open ntoll opened this issue 1 year ago • 2 comments

Use JavaScript's underlying fetch.

When in flight a "pending" card is shown. Two possible transitions can be called upon completion of the request:

  • success - a transition function that takes the result of the successful fetch call, and a reference to the datastore, and MUST return a string containing the name of the next card to show.
  • error - a transition function that takes the result of a problem call to fetch, and a reference to the datastore, and MUST return a string containing the name of the next card to show.

ntoll avatar Apr 03 '23 20:04 ntoll

Depends upon #38

ntoll avatar Apr 11 '23 11:04 ntoll

First draft of example straw-man code:

from pypercard import web

@my_app.transition("my_card", "click", "button")
def get_data(card, datastore):
    request = web.get("https://my_url.com/some/path/", ok="it_worked_transition", error="error_transition")
    # request.ok = ...
    # request.error = ...
    return "waiting_card"

The it_worked_transition and error_transition have a call signature like this:

def it_worked_transition(card, datastore, response):
    result = response.json()
    # ... do stuff ...
    return "next_card"

Under the hood we're using JavaScript's fetch and the response is a JS proxy object representing the actual response from the fetch call, once that call resolves.

We ought to pass through arguments like timeout, headers, and other stuff they may need. The web object has HTTP get, post, put, delete and info methods a la requests.

ntoll avatar Apr 11 '23 11:04 ntoll