Invoking Function With REST API
A function shall be invoked over any 3rd party web invocation using REST API that we provide. To use the REST API, the user will need to be authenticated using Lyrid JSON Web Token, the following sections describe how the token is generated and used by a HTTP web client (like curl) to authenticate and invoke a function that is generated by the user.
Token Authentication
To use the Lyrid using REST API, a JSON Web Token need to be generated. A token is an encrypted string that used to identify and authenticate the user per call against the platform. The endpoint for the authentication with the Secret Key and Access Key are as follows:
https://api.lyrid.io/auth
Examples :
echo '{"key":"<lyrid-key>","secret":"<lyrid-secret>"}' | curl -X POST -d @- https://api.lyrid.io/auth --header "Content-Type:application/json"
Example response:
{
"userId": "google-oauth2|110759572234590941878",
"accessKey": "34pQkHp7drouTGB2Z0ph",
>> "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik1ETkJPVGd6UTBNMVFUQTBNRGMzTlRjeE1EZzJNRVkwT0RVNFF6TkdNVGsxUTBKRVFURkNNQSJ9.eyJpc3MiOiJodHRwczovL2x5cmlkLmF1dGgwLmNvbS8iLCJzdWIiOiJRU3BBTzZ4R1h6Mnp3RTA4UXM4cndxT1F4VEpoeW9DNEBjbGllbnRzIiwiYXVkIjoiaHR0cHM6Ly9seXJpZC5pby9hY2Nlc3MvYXV0aCIsImlhdCI6MTU3Mzg1NzQ4OCwiZXhwIjoxNTczOTQzODg4LCJhenAiOiJRU3BBTzZ4R1h6Mnp3RTA4UXM4cndxT1F4VEpoeW9DNCIsImd0eSI6ImNsaWVudC1jcmVkZW50aWFscyJ9.M82Wf1VMq3pkkgKjwfix-PDUr3X4bVld5LzqbhBm2rpD-mEFsFjZTHbHhq4dsN_0DPuECgp8lPWMhW5pUU6x6GHl_J4OZYjseNYwAnjb1a58YkJM2Y6UD_MeIguyTS7KIIdJITytrCbFJ4qbHoxjApCEBuwupsUliP2Ple9Z7fU8FL2Dw2o-TJGJqeB72nnuQH0HcoQ2Z76VxNsOQMst95CrShO0a-oP1JOsTSprVXz7yR1VJm-m9rWCkhNHsyIBm3ssKaEUDnpGcwgAlcROa4jwnIfg70Xqtm1ZySug5_K_uWvj7V2ASsz2UyzRVNfTyhUg6w2HFUOashiNglp23Q",
"isValid": true,
"useCount": 1,
"creationTime": "2019-11-15T22:38:08.479758981Z",
"lastActivity": "2019-11-15T22:38:08.479759281Z",
"roles": {
"administration": {
"read": true,
"write": true
},
"function": {
"read": true,
"write": true
},
"credential": {
"read": true,
"write": true
},
"execute": {
"read": true,
"write": true
},
"policy": {
"read": true,
"write": true
}
}
}
The token field returned is the one that’s used to authenticate using Authorization Bearer.
REST Call
Getting Function ID
Before invoking a function , user needs to get the Function ID by calling:
lc code list --name "<app_name>" --module "<module_name>"
Note:
- Function ID changes every time the user submits a new revision of the module into the system.
- We're currently developing tag system to make invoking easier.
Executing The Function
To call the Lyrid function execution proxy, use these following URL with authorization bearer token from the authentication:
https://api.lyrid.io/api/serverless/app/execute/<function-id>/ANY
Examples :
curl -X POST https://api.lyrid.io/api/serverless/app/execute/<function-id>/ANY -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik1ETkJPVGd6UTBNMVFUQTBNRGMzTlRjeE1EZzJNRVkwT0RVNFF6TkdNVGsxUTBKRVFURkNNQSJ9.eyJpc3MiOiJodHRwczovL2x5cmlkLmF1dGgwLmNvbS8iLCJzdWIiOiJRU3BBTzZ4R1h6Mnp3RTA4UXM4cndxT1F4VEpoeW9DNEBjbGllbnRzIiwiYXVkIjoiaHR0cHM6Ly9seXJpZC5pby9hY2Nlc3MvYXV0aCIsImlhdCI6MTU3Mzg1ODQ4NSwiZXhwIjoxNTczOTQ0ODg1LCJhenAiOiJRU3BBTzZ4R1h6Mnp3RTA4UXM4cndxT1F4VEpoeW9DNCIsImd0eSI6ImNsaWVudC1jcmVkZW50aWFscyJ9.uTcVsXE7EcyQNlsPz2mVP4RFogp5UTeoOiuK8ZhzoHfwIx5blHrh2NoALvqF6hw-fJhCr4sDKe-2-cadd-Y0JxlIbJHbD26yWZ9uBhU7h7AKDq5t667nsDhehEvn-4ekRY3eq6Z67jS5DjKcxbLbAP4c7by17_ty2DrF22Ewv6aIZYfnxmvW3eTC5xPbGrulmHMQLHY41gnZaX6V3p0bTRRHI0ksIo89INJcRReQ-Lud7SlERfg8uANq7tAQwLf-e-mwGD5e6_aX8Ja_FPpG3DNoAyZ4sCK4oY37F9RqG41GnwELwCOTFa0yk3Hjf2xz13GSuw2lMAuTiZ32awNvSg"
Force Execute a Function on Specific Cloud
To force execution on a specific cloud framework, user can use the following link:
https://api.lyrid.io/api/serverless/app/execute/<function-id>/<framework>
Note: Framework is "AWS", "GCP", "LYR", or "ANY":
Passing Parameter
The Parameter can be passed in as JSON string into the body of the request. Examples :
echo '{"InputSample":"Hello"}' | curl -X POST -d @- https://api.lyrid.io/api/serverless/app/execute/<function-id>/LYR -H "Content-Type:application/json" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik1ETkJPVGd6UTBNMVFUQTBNRGMzTlRjeE1EZzJNRVkwT0RVNFF6TkdNVGsxUTBKRVFURkNNQSJ9.eyJpc3MiOiJodHRwczovL2x5cmlkLmF1dGgwLmNvbS8iLCJzdWIiOiJRU3BBTzZ4R1h6Mnp3RTA4UXM4cndxT1F4VEpoeW9DNEBjbGllbnRzIiwiYXVkIjoiaHR0cHM6Ly9seXJpZC5pby9hY2Nlc3MvYXV0aCIsImlhdCI6MTU3Mzg1ODQ4NSwiZXhwIjoxNTczOTQ0ODg1LCJhenAiOiJRU3BBTzZ4R1h6Mnp3RTA4UXM4cndxT1F4VEpoeW9DNCIsImd0eSI6ImNsaWVudC1jcmVkZW50aWFscyJ9.uTcVsXE7EcyQNlsPz2mVP4RFogp5UTeoOiuK8ZhzoHfwIx5blHrh2NoALvqF6hw-fJhCr4sDKe-2-cadd-Y0JxlIbJHbD26yWZ9uBhU7h7AKDq5t667nsDhehEvn-4ekRY3eq6Z67jS5DjKcxbLbAP4c7by17_ty2DrF22Ewv6aIZYfnxmvW3eTC5xPbGrulmHMQLHY41gnZaX6V3p0bTRRHI0ksIo89INJcRReQ-Lud7SlERfg8uANq7tAQwLf-e-mwGD5e6_aX8Ja_FPpG3DNoAyZ4sCK4oY37F9RqG41GnwELwCOTFa0yk3Hjf2xz13GSuw2lMAuTiZ32awNvSg"