OCI API Gateway can be used to manage access to your your integration apis. This post goes into a bit more details on the mechanics of such, for different types of integrations.
The initial setup of the gateway is detailed here.
Now to my integrations -
First HalloWelt -
Let's expose HalloWelt via the gateway.That's it - Pick up the endpoint, once created - Test from Postman -Now to test this from Postman, firstly I take the curl representation of the request -
and I drop it into Postman. I could also have copied the endpoint url from here -Now I expose this via the api gateway. For this to work, I need to set the following in the route -
I now run this from postman -
I get the following error in postman -
Exception while processing Trigger request for </ic/api/integration/v2/flows/rest/project/AA_LARGEFILEPROCESS/WRITELARGEFILETO_V2/1.0/file>. Error Message : Unsupported media type in the request
Let's include some more logic here - if the size of the file <= 1MB then route to integration A, else route to integration B. As you can see, I've added a new integration to my project.
I will cover 2 approaches here -
- use of an X header
- interrogate the Content-Length header. Here we need to interrogate the http header Content-Length. We could refer to this as ${request.headers[Content-Length]}.
Use of an X-Header
I create a new deployment and add the following rule to the route -
Test from postman, with the X-Large-File header set to N.Now test with the header set to Y.
Essentially we want to implement the following check - if content-length > 1MB then invoke the large file processing integration, else invoke the small file processing integration.
Net, net - ${request.headers[Content-Length]} > 1048576 (bytes).
Unfortunately, we cannot implement this directly in the api gateway. We need to implement a multi argument authorizer function, to take the value of content-length, cast it and perform the required comparison. Then we can set an auth context, such as backend = large_payload_service or small_payload_service. That auth context can then be used as the selector.
Here's the python code -
Now that we have the function, let's use it!