OCI REST for ESP32
|
The purpose of this library is to let you invoke Oracle Cloud Infrastructure (OCI) REST APIs directly from your device.
You should be familiar with the OCI REST APIs:
You should have already created the required keys and collected the necessary OCIDs. See Required Keys and OCIDs.
This library exists to make it easier to make calls to the OCI APIs from your microcontroller. The request signature process is somewhat complex, and it can be tricky to sign an HTTPS request from a memory constrained device. I created this library to simplify the process.
Please note! This library has only been successfully tested on an ESP-32. It has not been tested on any other board, and probably won't work on any other board due to memory constraints and dependent libraries.
The latest documentation always lives at: https://recursivecodes.github.io/oci_rest_api_esp32/html/index.html
Declare some variables to hold your keys and OCIDs. Keep this out of source control!
Pass in your tenancyOcid
, userOcid
, keyFingerprint
, apiKey
. If your private key is password protected, pass the password in as the 5th argument.
Construct an instance of the Oci
class, passing in your profile. This will initialize the API class and configure the NTP server needed to obtain a timestamp to include with each request.
Construct a request object. Pass in the REST endpoint host, the path, HTTP method as the first 3 arguments.
The example above makes a secure request because a copy of the endpoint's Root CA Cert is passed in as the final argument. You can get a copy of the Root CA Cert many ways. Here's an example using openssl
on *nix compatible systems:
If you want to make the request insecure (the Root CA Cert will not be validated), pass NULL
in instead of the cert.
If you want/need to add request headers to the API call, construct and pass an array of Header
structs in argument 4 and the length of that array in argument 5.
Construct a response object. This will ultimately hold the results (or any errors) of your API call.
If you want/need to retrieve any headers from the API response, construct and add an array of Header
structs. Just add the name of the header to retrieve, the value will be populated when the API call is complete.
Call the apiCall()
method of Oci
, passing the request and response objects.
If successful, the statusCode
property of the response object will be populated with 200
. You can then print/handle the result as needed. In this example, I'm deserializing the JSON string into an object.
The previous example might produce output such as this: