FIN5 as Client using Axon
Please note, there is also an existing API called ioReadJson() that enables a developer to GET data from an endpoint. This function doesn’t support additional HTTP headers or different HTTP verbs (only GET).
These Axon functions are available fromFIN 5.0.6 onward.
Introduction
This document provides some practical example usage of how to implement REST APIs in FIN, using Axon programming language.
Here are some examples of using the FIN HTTP Axon APIs:
GET some JSON data and write it to Folio
GET some data from a REST API
The response can handle both Zinc and JSON encodings.
If JSON, it attempts to decode it as a Grid.
If it can’t be parsed as a JSON Grid then it’ll convert the vanilla JSON into a Grid.
Add a marker tag so the record can be easily reference again
Remote the id property so the data can be committed to Folio without any errors
If the record already exists then update the record with the new data
() => do
res: finHttpGet(`https://jsonplaceholder.typicode.com/todos/1`)
.first
.set("restApiResult", marker())
.remove("id")
rec: read(restApiResult, false)
if (rec == null)
diff(null, res, {add}).commit
else
diff(rec, res).commit
endTo regularly pull data from the Cloud, try using the above code in a job.
GET some JSON data with an authorization bearer token
Write the secure token to the project database. Never hard code security tokens in Axon script.
passwordSet("FIN_AUTH_TOKEN_MYTOKEN", "mySuperSecretPassword")GET some data from a REST API
Reference the authorization token and add it to the outgoing HTTP request with an
Authorizationheader with a bearer token value
finHttpGet(
`http://localhost:8088/mySecureApi`,
{ authorization: "Bearer $FIN_AUTH_TOKEN_MYTOKEN" }
)POST a JSON encoded Grid to an HTTPS end point
readAll(site).finHttpPost(`https://postman-echo.com/post`, {"Content-Type": "application/json"})PUT a Zinc encoded Grid to an HTTPS end point
readAll(site).finHttpPut(`https://postman-echo.com/post`)Best Practices
Keep Axon logic small and explicit
Use jobs or tasks for periodic calls
Move to Fantom if complexity grows, or if you need to authenticate with a login API or with a rotating token