API Element Plugin
Introduction
The API Element Plugin extends the functionality of the default API elements available in the API Builder. This plugin type must extend the org.joget.api.model.ApiPluginAbstract
abstract class, providing additional capabilities to your Joget application.
Get started
POM file adjustments
Add the following dependency to your project's POM file:
Abstract class
org.joget.api.model.ApiPluginAbstract
- Under apibuilder_api module
- Extended org.joget.plugin.base.ExtDefaultPlugin. See Plugin Base Abstract Class and Interface.
- Implemented org.joget.api.model.ApiPlugin.
- A base abstract class to develop a custom API Element Plugin.
Configure API methods
To generate JSON APIs from your implementation, utilize the following annotations:
@Operation
- path (String): Define the API path.
The API path name to call the method. Always start with a forward slash ( / ).
To include path parameters, after annotating @Param with the method parameter (see doc below), you can add the variable enclosed within curly braces into the path. - type (enum): Defines the request method type.
Available types:
- Operation.MethodType.GET
- Operation.MethodType.POST
- Operation.MethodType.PUT
- Operation.MethodType.DELETE
Default value when undefined is Operation.MethodType.POST.
- summary (String): Provides a brief description of this operation. This is the value to display as the method name in the API Builder. It is recommended that the text be 120 characters or less for proper visibility when previewing API.
Default value when undefined is a blank string.
- description (String): A verbose description of the operation. Default value when undefined is a blank string.
- deprecated (boolean): Allows an operation to be marked as deprecated. Default value when undefined is false.
@Responses
- responseCode (int): HTTP response code.
- description (String): A short description of the response. Default value when undefined is a blank string.
- definition (String): A definition of the data schema in response. Default value when undefined is a blank string.
- dataClass (String): A class to the data in response. Default value when undefined is a blank string.
- contentType (String): A content type of the data in response. Default value when undefined is application/json.
- array (boolean): Defines if this response value is an array. Default value when undefined is false.
@Param
- value (String): A short name of the parameter.
- required (boolean): Defines if this parameter value is mandatory. Default value when undefined is true.
- description (String): A verbose description of the parameter. Default value when undefined is a blank string.
- definition (String): The key of definition provided by ApiPlugin. Default value when undefined is a blank string.
- header (boolean): Defines if this parameter value is in the request header. Default value when undefined is false.
Here’s a sample code snippet from the Basic Current User API plugin:
Abstract methods
getIcon
Returns the icon for this API element in the API Builder palette.
public String getIcon()
getTag
Returns a unique tag for the API document.
public String getTag()
Overridable methods
getTagDesc
Return a tag description for the API Document. By default, it will return the value found in your custom plugin's getLabel() method.
public String getTagDesc();
getResourceBundlePath
Return a resource bundle path for API document generation. Default value is NULL.
public String getResourceBundlePath();
getExternalDocsDesc
Return a short description for external document for API document. Default value is NULL.
public String getExternalDocsDesc();
getExternalDocsURL
Return a link for external document for API document generation. Default value is NULL.
public String getExternalDocsURL();
getDefinitions
Return a key & JSON Definition map for API document generation. Default value is NULL.
public Map<String, ApiDefinition> getDefinitions();
isAPIEnabled
Check if an API path is enabled for the API Key. The default behavior checks if a method exists in the specified path, in the property string "ENABLED_PATHS."
public Boolean isAPIEnabled(String method, String path);
getOperationOptions
Return a map of available operations (GET, POST, PUT, DELETE) to populate in the builder.
public Map<String, String> getOperationOptions();
usingSimpleConfig
A flag to indicate using simplified plugin configuration method. Default value is TRUE.
public boolean usingSimpleConfig();