API Generation
Create the signature for your API
Modus automatically creates an external API based on the endpoints defined in your app manifest. Modus generates the API signature based on the functions you export from your app.
Exporting functions
Modus uses the default conventions for each language.
Functions written in Go use starting capital letters to expose functions as public. Modus
creates an external API for public functions from any file that belongs to the main
package.
The functions below generate an API endpoint with the signature
Since the classify
function isn’t capitalized, Modus doesn’t include it in the
generated GraphQL API.
Functions written in Go use starting capital letters to expose functions as public. Modus
creates an external API for public functions from any file that belongs to the main
package.
The functions below generate an API endpoint with the signature
Since the classify
function isn’t capitalized, Modus doesn’t include it in the
generated GraphQL API.
Functions written in AssemblyScript use ES module-style import
and export
statements. With
the default package configuration, Modus creates an external API for functions exported form the
index.ts
file located in the functions/assembly
folder of your project.
The functions below generate an API endpoint with the signature
Since the classify
function isn’t exported from the module, Modus doesn’t
include it in the generated GraphQL API.
Generating mutations
By default, all exported functions are generated as GraphQL queries unless they follow specific naming conventions that indicate they perform mutations (data modifications).
Functions are automatically classified as mutations when they start with these prefixes:
mutate
post
,patch
,put
,delete
add
,update
,insert
,upsert
create
,edit
,save
,remove
,alter
,modify
For example:
getUserById
→ QuerylistProducts
→ QueryaddUser
→ MutationupdateProduct
→ MutationdeleteOrder
→ Mutation
The prefix is detected precisely - addPost
becomes a mutation, but
additionalPosts
remains a query since “additional” doesn’t match the exact
“add” prefix pattern.