I'm using Marimo as an API playground. It works very well, Marimo seems very suitable. Can I make it simpler? Now each HTTP request requires two cells - one for request, another for response - and a tuple of
some_endpoint, some_endpoint_button
. Is it possible to implement it in one cell and/or avoid exposing button variable?
Bonus question: how do I implement a "copy as curl" button? I can't find functionality to deal with system clipbard.
@app.cell
def _(config, private):
admin_projects, admin_projects_button = private.request('GET', f'/admin/user/{config.user_id}/projects')
admin_projects
return admin_projects, admin_projects_button
@app.cell
def _(admin_projects, admin_projects_button):
admin_projects.run(admin_projects_button)
return
In this example
private.request()
returns
(Request, mo.ui.run_button)
tuple:
def request(self, method, url, *, json = None):
return (
Request(
method,
f'{self.base_url}{url}',
json=json,
auth=self.auth,
timeout=self.timeout,
client=self,
),
mo.ui.run_button(label='send'),
)
And
Request.run()
uses
mo.stop
and
mo.status.spinner
:
def run(self, button):
mo.stop(not button.value, mo.md('press *send* โ๏ธ'))
with mo.status.spinner(subtitle='Loading...') as _spinner:
response = self.send()
return response