Global object 'g.'
Global object 'g'
g.req
- The 'g.req' will get the requested API data.
headers
- Get/Set requested API headers.
params
- Get requested API params.
query
- Get/Set requested API query params.
body
- Get/Set requested API body object.
eventData
- Existing event data will be get in 'eventData'.
auth
- Requested API's authorization related data get in 'auth'.
- We have multiple authorizations in 'g.req.auth'.
- authAMUser - API user authorization
- authAMDB - Database user authorization
- authGoogle - Google user authorization
- authAWS - AWS Cognito authorization
- authAzure - Azure Active Directory authorization
g.res
- Requested API's whole response gets in the 'g.res'.
- 'g.res' used in Post hook. If AM user sets the response statusCode in the pre hook, it will replace with the actual API response statusCode after executing the API code.
statusCode
- Get the HTTP response status code of the requested API.
All supported status code.
OK = 200
NO_CONTENT = 204
CREATED = 201
BAD_REQUEST = 400
UNAUTHORIZED = 401
FORBIDDEN = 403
RESOURCE_NOT_FOUND = 404
INTERNAL_SERVER_ERROR = 500
contentType
- Get a response as per the given content type in the custom API code.
- The user does not need to set the response content type to send JSON as a response.
- If the response content type is not set that means it is application/JSON.
If ContentType is set to below system will return data accordingly.
JSON = 'application/json'
XML = 'text/xml'
YAML = 'text/yaml'
TEXT = 'text/plain'
HTML = 'text/html'
Note: If the content type is set and not from the above list, then API Maker will consider it as base64 encoded.
output
- Get actual response data.
shared
- It is the API Maker's variable. Share values between Pre-Post hooks.
errors
- If any errors in the response it will get in this.
warnings
- If any warnings in response it will get in this.
g.sys
g.sys.db
- Call instance schema APIs.
All 'g.sys.db' methods list.
- getAll
- getAllByStream
- getById
- saveSingleOrMultiple
- masterSave
- arrayOperations
- updateById
- updateMany
- replaceById
- removeById
- query
- queryByStream
- removeByQuery
- aggregate
- count
- distinct
- distinctQuery
g.sys.db.gen
- Call instance generated APIs.
- Instance generated APIs is schemaless. It is used only for MongoDB.
All 'g.sys.db' methods list.
- getAllGen
- getAllByStreamGen
- getByIdGen
- saveSingleOrMultipleGen
- masterSaveGen
- arrayOperationsGen
- updateByIdGen
- updateManyGen
- replaceByIdGen
- removeByIdGen
- queryGen
- queryByStreamGen
- removeByQueryGen
- aggregateGen
- countGen
- distinctGen
- distinctQueryGen
g.sys.cache
- To do operations on cache use 'g.sys.cache' methods.
Set redis keys
Set redis key using global object 'g'.
All 'g.sys.cache' methods list.
- getKey
- setKey
- removeKey
- resetCacheDB
- resetCacheThirdPartyApis
- resetCacheCustomApis
- resetCacheSystemApis
g.sys.system
- API Maker provides intellectual system APIs to do your work smartly.
- encrypt
- decrypt
- hash
- getToken
- callExternalApi
- executeQuery
- getSecret
- getTableMeta
- emitEvent
- emitEventWS
- isValidDataForTable
- isValidDataForCustomAPI
- isValidDataForThirdPartyAPI
g.logger
- To print logs while coding API Maker user can use 'g.logger' methods.
g.shared
- Shared space can be used to hold some variables, functions, and database connections.
- To shared variables between pre hook, post hook, custom API code, and utility code.
- You can use it globally. like,
g.shared.preHookArr = [3.14, 108];
g.shared.hello = "World";
g.shared.name = {
Fname: "Bob",
Lname: "Alice"
};
In Pre hook, set 'count' variable 234.
Use 'count' in post hook.
Define an object directly in a shared variable, its scope will be limited to that specific code panel. like,
For clear shared space,