Custom APIs, hooks, events, schedulers, migrations, process initializers and test cases all receive the same global object g. Every page of this section is one method of it, with examples you can paste into the editor of the admin panel, in every language : pick yours in the tabs, and every page shows it from then on.
Every piece of code is the function main of its language ; the examples are the inside of it :
import*asTfrom'types';// the types of API Makerimport*asdbfrom'db-interfaces';// the interfaces generated from your schemasasyncfunctionmain(g:T.IAMGlobal){// your code, with await on every call of g.sysreturn{hello:'world'};// what the caller receives in data}module.exports=main;
fromamimportGasyncdefmain(g:G):# your code, with await on every call of g.sys (a coroutine ; `def main` works too, without await)return{'hello':'world'}# what the caller receives in data
filestaticclassApi{publicstaticasyncTask<object?>Main(Gg){// your code, with await on every call of g.Sysreturnnew{hello="world"};// what the caller receives in data}}
packagecodeimport"apimaker/am"funcMain(g*am.G)(any,error){// your code : every call of g.Sys answers with its errorreturnam.M{"hello":"world"},nil// what the caller receives in data}
useam::{Errors,G,Value,json};pubfnmain(g:&mutG)->Result<Value,Errors>{// your code : ? after every call of g.sysOk(json!({"hello":"world"}))// what the caller receives in data}
importam.G;importjava.util.Map;classApi{staticObjectmain(Gg){// your code : every call of g.sys answers at oncereturnMap.of("hello","world");// what the caller receives in data}}
importam.Gfunmain(g:G):Any?{// your code : every call of g.sys answers at oncereturnmapOf("hello"to"world")// what the caller receives in data}
Every language gets the same g, written the way the language writes things (g.sys.db.get_all in Python, g.Sys.Db.GetAll in C# and Go) : see Languages and runtimes.
A g.sys call returns data and throws the errors, so the caller of your API gets them. The whole response envelope, which never throws, comes with true as the second argument in TypeScript (const res = await g.sys.db.count({ ... }, true); if (!res.success) ...), and through full in the other languages (res = await g.sys.db.full.count(...) in Python, g.Sys.Db.Full.Count(...) in C# and Go).