RESTful APIs
How to build RESTful APIs in Elements
Elements 3.0 Provides a complete implementation of Jakarta RESTful Web Services 4.0.0. The full usage of Jakarta RS is beyond the scope of this document. What you need to know most:
Jakarta RS Allows you to generate RESTful endpoints for your game's code which can be called from in-engine code using any standard HTTP client library.
Specific endpoints are developed using a set of annotations in Java code and handled automatically by the application container.
Existing RESTul APIs can be imported directly into an Element with almost no modification.
Steps to Defining a Jakarta RS Element
To use the Jakarta RS in your own Element, you must perform the following steps:
Define the Element by annotating the
package-infotype in your code.Add all compiled classes and jars into the Element package structure.
Expose the
Applicationtype as a service.
Complete Example Code
The following example walks through the necessary files to define a simple endpoint for CRUD (Create, Read, Update, Delete) operations for a message based service.
Step 1: Define the Element
@ElementDefinition
package dev.getelements.elements.sdk.test.element.rs;
import dev.getelements.elements.sdk.annotation.ElementDefinition;Step 2: Define the Application
Step 3: Define the Endpoint Code
Step 4: Ensure all Dependencies are Included
Last updated