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 main example covers routing to different integrations, based on Content-Length. The use case is that of processing a file; files over 5MB are classed as large files, those <= 5MB are classed as small files.
I begin with a simple German version of Hello World, to get us started.
The initial setup of the OCI Gateway is simple. For those who want a step by step, check out my post 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 <= 5 MB 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 > 5 MB then invoke the large file processing integration, else invoke the small file processing integration.
Net, net - ${request.headers[Content-Length]} > 5242880 (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!
Some things to note
OCI API Gateway has a limit of 20MB on request body size.The first execution of the function includes ramp up time, so expect this first invoke to take a little longer.
Log files for OCI API Gateway and Functions
Testing
Small file test: