Ingesting APIStar registered routes


#1

Hey y’all,

I’m new to APIStar and I’ve been playing around with it for a bit now. I’m writing a wrapper API around youtube-dl and I’m curious if there is an easy (read: easier) way to use/ingest routes that are registered.

In my case, a route (POST /job) creates and executes a future that actually runs the youtube-dl job. The only context I am giving the executor is job metadata (ie., url, profile, etc) and the encoding profile.

I’ve tried creating a new SQLAlchemy session to set job information (status, progress, etc), but that doesn’t seem to work as I wish. It seems like the only thing I can do is expose a new endpoint (PUT /job/{job_id}) to update status and such.

So – is there any easy way to make requests against APIStar routes, given an instance of frameworks.asyncio.AsyncIOApp or similar? The only solution I can really come up with includes service discovery to figure out what to request against (host/port-wise), which sounds remarkably unpleasant.

I can share the code if it helps answer the question, but I’d like to keep it to myself until it becomes a little bit prettier :slight_smile:


#2

I’m not sure I fully understand the question. If you’re trying to find the canonical url to post against, there is reverse_url function. So if you have a route with the name “job”, then app.reverse_url(‘job’) will return the full URL. I often pass url=app.reverse_url to templates so that {{ url('auth') }} will work.

If you’re looking to make client requests from another instance of the code, apistar has a TestClient. It’s mainly used for the test framework, but you can probably use it to do the trick.

from app import app
from apistar import TestClient

def test_hello_world():
    client = TestClient(app)
    response = client.get('/hello_world/')