Every piece of code you write in API Maker, a custom API, a hook, an event listener, a scheduler, a migration, a process initializer, a test case, is a function of one argument :
The request headers, editable : a pre hook can set x-am-content-type-response for the whole call.
params
The path parameters : instanceName, database, collection, id, primaryKey, field and order of distinct, tenantUsername for a multi-tenant request…
query
The query parameters as an object : find, select, limit… editable in a pre hook, which is how row level security is done.
body
The body, editable.
eventData
The data of the event, in an event listener.
auth
The opened tokens : authAMUser (the API user), authAMDB (the person, from a DB auth provider), authCustom, authGoogle, authAWS, authAzure.
reqInfo
url, apiCategory, reqMethod and apiInfo (id, name, schemaType) : which API is running.
isApiRequestFromUser
true for an HTTP request, false for a call made from code.
Who is calling
constperson=g.req.auth.authAMDB;// the row of your users table, minus its passwordconstapiUser=g.req.auth.authAMUser;// name and groups of the API user
T.EStatusCode.OK (200), CREATED, NO_CONTENT, BAD_REQUEST, UNAUTHORIZED, FORBIDDEN, RESOURCE_NOT_FOUND, INTERNAL_SERVER_ERROR… Set by your code, it wins over the one of the API.
Your own keys in Redis and the cache resets : getKey, setKey, removeKey, resetCacheDB, resetCacheCustomApis, resetCacheSystemApis, resetCacheThirdPartyApis. Examples.
g.sys.test
In a test case only : runCustomApi, mock, clearMocks, calls.
Every g.sys.db call takes the same headers and queryParams an HTTP call takes, and runs with the groups of the API user of the request. Hooks are skipped unless you pass skipHookRunning: false.
Pass true as the last argument (getFullResponse) to get the whole { success, data, errors, … } envelope instead of data.
g.logger.log('order ',order._id);// with the response on the testing pages, in the logs of a log profileg.logger.error('payment failed : ',e.message);g.shared.count=234;// set in a pre hook…constcount=g.shared.count;// …read in the post hook of the same request
debug, log, info, warn and error write the same line : the level is not kept. The arguments are joined without a separator, objects are printed as indented JSON. The calls are synchronous, no await.
For an error, log e.message or e.stack.
On the native process (runOnNativeProcess), console.log is not captured : use g.logger.