You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
is there a simple way to call an API method from inside a resource Handler?
I'm implementing an API that has HATEOAS _embedded (which includes content for performance reasons). Ex: { ... data ..., "_embedded" : { "/session" : { ... data for GET /session ... } } }
For what i can see, the testing classes have a way to emulate a WSGI call, but not sure if there is a way to make requests to the main API for routing and all.
Any help appreciated!
The text was updated successfully, but these errors were encountered:
Hi @jcampanello, sorry for the delay in responding. There's no feature for internal routing currently, although you can certainly just call the on_* responder method directly, or factor out the logic to a third method. I'll schedule this as a possible feature for 2.x since we've been getting a number of requests along these lines.
I actually took the code from the tests to implement API call with WSGI emulation. I think this provides for better modularity, otherwise a module implementing part of the API should know about other modules implementing other parts (granted, the API path is coupling, but could be passed as a parameter on handler creation).
The most important benefit of this approach, i think, is when you make the request through WSGI emulation you get to benefit from all the middleware installed in the API. Ex: user and customer access control (is customer paying for the salary module and does user X has permissions to access salary module), middleware level caching, ip access control, etc.
This derives into an important requirement (for my implementation, at least) that to make the simulated request, i should start from the current request (and response) and copy at least header fields (except: CONNECTION, QUERY_STRING, session, ACCEPT-ENCODING, COOKIE, CONTENT-LENGTH, CONTENT-TYPE) and the cookies. This is to support authentication tokens, host identifiers, api special headers, etc. The current response is required because some cookies could be set on it that should go in the next requests (as if the actual client made it).
Well, i've wrote this only in case you decide to add it as a feature, to state some things i think should probably be considered.
Thanks for the response (and for falcon!). Regards
Hi,
is there a simple way to call an API method from inside a resource Handler?
I'm implementing an API that has HATEOAS _embedded (which includes content for performance reasons). Ex:
{ ... data ..., "_embedded" : { "/session" : { ... data for GET /session ... } } }
For what i can see, the testing classes have a way to emulate a WSGI call, but not sure if there is a way to make requests to the main API for routing and all.
Any help appreciated!
The text was updated successfully, but these errors were encountered: