N NezamDocumentation

API grammar#

API grammar describes HTTP-style integration declarations, endpoint methods, request and response shapes, and route bindings.

Source#

PropertyValue
Grammar filepackages/business/language/grammar/api.g4
Grammar nameapi
Grammar kindparser
Importscommon, type, expression, literal
Imported byBusinessLanguage, module
Direct rule or token count14

How to use this page#

Read the examples first when authoring Business Language. Use the rule inventory when checking exact grammar coverage or when updating parser, lowering, editor, or documentation behavior.

Entry rules and syntax families#

Start with these rules when reading this grammar: apiDeclaration, routeDeclaration, routeBody, endpointDeclaration, methodBody, functionReturnType.

  • Declarations: apiDeclaration, endpointDeclaration, routeDeclaration
  • Types: functionReturnType
  • Bodies: methodBody, routeBody

Key grammar excerpts#

apiDeclaration#

antlr
apiDeclaration
    : API identifier OPEN_BRACE apiMemberList? CLOSE_BRACE
    ;

routeDeclaration#

antlr
routeDeclaration
    : ROUTE httpMethod stringLiteral routeBody
    ;

routeBody#

antlr
routeBody: OPEN_BRACE routeMemberList? CLOSE_BRACE;

Complete rule and token inventory#

text
apiDeclaration, apiMember, apiMemberList, endpointDeclaration, functionReturnType, httpMethod, methodBody, parameter
parameterList, routeBody, routeDeclaration, routeFunction, routeMember, routeMemberList

Examples#

No-parameter endpoint#

bl
api VendorApi {
  get "/vendors" list_vendors(): Json;
}

Typed endpoint with block body#

bl
api InvoiceApi {
  post "/invoices" create_invoice(payload: Json): Json {
    return payload;
  }
}

Route-local functions#

bl
api InvoiceApi {
  route get "/invoices" {
    async function list(company_code: CompanyCode) -> Json;
  }
}

Options endpoint and patch route#

bl
api HealthApi {
  options "/health" health_options;

  route patch "/vendors" {
    function update(payload: Json, dry_run: bool = false): Json {
      return payload;
    }
  }
}

Common authoring mistakes#

  • Do not copy examples without checking the rule inventory for the exact grammar boundary.
  • Do not add behavior that depends on missing configuration or undeclared user-facing errors.
  • /language/services-apis/
  • /language/functions-services/

Authoring notes#

  • Keep examples aligned with the grammar source, not with inferred syntax from another language.
  • Use declared messages for user-facing failures, and fail closed when required configuration is absent.
Source: packages/business/language/grammar-files/api.md