Mokapi JavaScript API
Mokapi provides a powerful JavaScript API that allows you to extend its functionality. This documentation outlines the available modules and their capabilities. To learn how Mokapi handles module imports, see Modules.
tip
Mokapi offers a TypeScript definition package. Install it using: `npm install @types/mokapi --save-dev`
Available Modules
mokapi (Core API)
Provides core functions for scheduling jobs, handling events, and accessing environment variables.
Functions | Description |
---|---|
cron( expression, handler, [args] ) | Schedules a new periodic job using a cron expression. |
date( [args] ) | Returns a formatted date string. |
env( name ) | Gets the value of an environment variable. |
every( interval, handler, [args] ) | Runs a periodic job at a fixed interval. |
on( event, handler, [args] ) | Registers an event handler. |
sleep( time ) | Pauses execution for a specified duration. |
marshal( value, [encoding] ) | Converts a value to a marshaled string. |
mokapi/http (HTTP Requests)
Functions to send HTTP requests within Mokapi scripts.
Functions | Description |
---|---|
get( url, [args] ) | Sends an HTTP GET request. |
post( url, [body], [args] ) | Sends an HTTP POST request |
put( url, [body], [args] ) | Sends an HTTP PUT request |
head( url, [args] ) | Sends an HTTP HEAD request |
patch( url, [body], [args] ) | Sends an HTTP PATCH request |
delete( url, [body], [args] ) | Sends an HTTP DELETE request |
options( url, [body], [args] ) | Sends an HTTP OPTIONS request |
mokapi/faker (Mock Data Generator)
Generates random test data based on a schema.
Functions | Description |
---|---|
fake( schema ) | Generates mock data based on a schema. |
mokapi/kafka (Kafka Messaging)
Functions for interacting with Kafka topics.
Functions | Description |
---|---|
produce( [args] ) | Publishes a message to a Kafka topic. |
mokapi/mustache (Template Engine)
Processes Mustache templates with dynamic data.
Functions | Description |
---|---|
render( template, scope ) | Renders a Mustache template with provided data. |
mokapi/yaml (YAML Parsing & Serialization)
Handles YAML data parsing and conversion.
Functions | Description |
---|---|
parse( text ) | Parses a YAML string into a JavaScript object. |
stringify( value ) | Converts a JavaScript object into YAML format. |
mokapi/encoding (Encoding Utilities)
Functions for encoding and decoding data.
Functions | Description |
---|---|
base64.encode( input ) | Encodes a string using Base64. |
base64.decode( input ) | Decodes a Base64-encoded string. |