invent
invent copied to clipboard
It should be possible to make HTTP requests to and endpoint and process the result
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 theresult
of the successfulfetch
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 theresult
of a problem call tofetch
, and a reference to the datastore, and MUST return a string containing the name of the next card to show.
Depends upon #38
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
.