Evaluating the microservice ID
The portal_id
parameter will automatically be fetched and evaluated using a dependable function that is injected into the APIRouter
instance where the API endpoint is implemented. As discussed in Chapter 3, Investigating Dependency Injection, a dependable function or object can serve as a filter or validator of all incoming requests of any services once injected into an APIRouter
or FastAPI
instance. The dependable function used in this ERP prototype, as shown in the following script, evaluates whether the portal_id
parameter is 1
, 2
, or 3
only:
def call_api_gateway(request: Request): portal_id = request.path_params['portal_id'] print(request.path_params) if portal_id == str(1): raise RedirectStudentPortalException() elif portal_id == str(2): raise...