Introduction
The Caliper API is a public-facing interface built with the SDK. Its purpose is to empower external systems without direct access to the SDK, providing them means to leverage Q2’s online banking functionality. To learn more about the API, please navigate to the Caliper API Documentation.
Among the various endpoints offered within the API, the Custom Endpoint stands out as it allows for SDK extensions to be called by the API. This tutorial will walk through building and installing an SDK extension that can then be accessed by the API. This extension type is a powerful tool that will allow for public facing functionality with built in authentication.
It’s important to note that this tutorial is closely tied to the API tutorial. If you haven’t started with the API tutorial, we recommend beginning there.
Task
In this tutorial, a new custom endpoint extension will be created and installed. By default, a get
and post
function will be generated. We will override both methods:
The get
function to fetch product or product type information, and the post
function to update account nicknames. Once implemented and installed,
a request can be made to the Caliper API to test the extension locally.
Creating the Extension
Let’s create a new extension:
$ q2 create_extension TestCustomEndpoint
Note
Similar to the online banking tutorial, only one extension named “TestCustomEndpoint” can exist in the database! If other developers at your organization are working through this tutorial, be sure to provide a unique name for your extension.
This will present a menu of different extension types that can be created. Select the “Caliper API Custom Endpoint” option which will generate all the necessary files and directories needed for the extension.
The extension.py file will contain the get
and post
functions, which will be invoked based on the HTTP verb use in the API request. These methods belong to a class that inherits from the Q2CaliperAPICustomHandler
class which abstracts away some of the complexities, providing various attributes to facilitate interactions between the SDK and API.
The return_data
method will ensure that the returned data is shaped in a way that the Caliper API can consume. Query parameters and body arguments will be collected and placed into a dictionary called self.request_parameters
. If there are any configurations stored in the database for this extension, they will be collected by the API, sent along in the request, and then placed in the self.wedge_address_configs
variable.
Note
This extension type does not support WedgeOnlineBanking calls as the requests must be initiated by HQ. Instead Q2API endpoints can be utilized, as will be demonstrated in the next portion of the tutorial. For more information on the difference between WedgeOnlineBanking and Q2API, please visit our HQ API documentation.