tarilabs / jsr223-powerfx

A JSR-223 implementation for evaluating Power Fx formulas (expression) by making use of a server implemented on F# and .NET platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This is an Open Source community project.

JSR-223 Power Fx

A JSR-223 implementation for evaluating Power Fx formulas (expression) by making use of a server implemented on F# and .NET platform.

sequenceDiagram
    participant J as Your Java App
    participant I as <<interface>><br/>JDK JSR-223
    participant E as This JSR-223<br/>ScriptEngine
    participant S as This .NET server<br/>(Docker image)
    link I: Guide @ https://docs.oracle.com/en/java/javase/14/scripting/java-scripting-api.html
    link I: JavaDoc @ https://docs.oracle.com/en/java/javase/17/docs/api/java.scripting/javax/script/package-summary.html
    J->>I: 
    I->>E: 
    E->>S: POST /eval<br/>(JSON)
    S-->>E: Power Fx eval result<br/>(JSON)
    E->>I: 
    I->>J: 

How to use

Run docker image with:

docker run -p 80:5000 jsr223-powerfx-server

Include this dependency in your Java project.

Using Maven:

<dependency>
    <groupId>com.matteomortari</groupId>
    <artifactId>jsr223-powerfx</artifactId>
    <version>0.1</version>
    <scope>runtime</scope>
</dependency>

Example usage:

ScriptEngineManager MANAGER = new ScriptEngineManager();
ScriptEngine engine = MANAGER.getEngineByName("powerfx");
Bindings bindings = engine.createBindings();
bindings.put("a", 1);
bindings.put("b", 2);
Object result = engine.eval("a+b", bindings); // result = 3

FAQ

Q: Why F# ?
A: No particular reason, I've always been looking for an excuse to experiment using it; luck is being prepared when the opportunity comes :)

Q: Is it "production-ready"?
A: This is a chabuduo MVP working-PoC

Q: I have a feedback/question?
A: Feel free to contact me!

References

Helpful references I've used while building this experiment

About

A JSR-223 implementation for evaluating Power Fx formulas (expression) by making use of a server implemented on F# and .NET platform

License:Apache License 2.0


Languages

Language:Java 54.1%Language:F# 42.1%Language:Dockerfile 3.8%