Route arguments and views


So I’ve been reveling in APIstar of late, and really enjoying the DI / Component machinery.

Since I had a few functions that did the same work, taking a client_id argument and getting a Client record from the DB, I moved that work into a Component.

This worked fine, except when I removed the client_id: int from the function definition, apistar complained:

apistar.exceptions.ConfigurationError: URL Argument “client_id” missing from view “<function client_update at 0x7f49664f6048>”.

The init function for my Client object takes the client_id, obviously.

IS there any way to tell API* this argument is consumed elsewhere? Or am I doing this wrong?


Could we see some code?

def find_client(client_id: int,
                session: Session,
                account: Auth
               ) -> models.Client:
        '''Retrieves the Client specified, only if it's attached to this Account.'''
        return session.query(models.Client).filter(
            models.Client.account_id == account.get_user_id(),
   == client_id,
        raise NotFound()

Component(models.Client, init=find_client),

def client_update(client_id: int,
                  client: models.Client,
                  data: schema.Client,
                  session: Session,
                 ) -> schema.Client:


Upon further reflection of Tom’s goals, this really violates expectations… but it was a nice experiment with DI and components :smiley: