Skip to content

likespro/lpfcp-java

Repository files navigation

likespro avatar

LPFCP Java

Expose your functions to the network with just one annotation

LICENSE GitHub Contributors Issues GitHub pull requests

Build Passing Git Size Git File Count Git Lines Of Code

LikesPro Function Call Protocol (LPFCP) Java lets you expose ordinary Java and Kotlin classes as remote-callable services with a single annotation. LPFCP Java implements the LPFCP protocol — check out the LPFCP protocol specification — and provides both server and client parts instrumentals.


Features

  • 🌐 Annotation-Driven – Turn any Java/Kotlin class object into an HTTP-accessible service by annotating your functions to expose.
  • 🚀 Lightweight – Minimal dependencies and overhead; ideal for microservices and serverless deployments.
  • 🔌 Java & Kotlin Support – Use LPFCP from either language with the same ease.
  • 🛠 Zero-Boilerplate – No manual serialization or wiring; LPFCP takes care of it using reflection.

Read our Wiki


Getting Started

Installation

Gradle:

dependencies {
    implementation("io.github.likespro:lpfcp-core:1.1.0") // Core features: getProcessor, .processRequest, etc.
    implementation("io.github.likespro:lpfcp-ktor:1.1.0") // Integration with Ktor, for servers: lpfcpServer, Route.lpfcp, etc.
}

Maven:

<!-- Core features: getProcessor, .processRequest, etc. -->
<dependency>
    <groupId>io.github.likespro</groupId>
    <artifactId>lpfcp-core</artifactId>
    <version>1.1.0</version>
</dependency>

<!-- Integration with Ktor, for servers: lpfcpServer, Route.lpfcp, etc. -->
<dependency>
    <groupId>io.github.likespro</groupId>
    <artifactId>lpfcp-ktor</artifactId>
    <version>1.1.0</version>
</dependency>

Usage

1. Define Your Interface (Shared Code)

interface Calculator {
    fun add(a: Int, b: Int): Int
    fun subtract(a: Int, b: Int): Int
}

2. Implement & Annotate (Server Code)

Annotate your implementation class functions with @LPFCP.ExposedFunction:

class CalculatorImpl : Calculator {
    @LPFCP.ExposedFunction
    override fun add(a: Int, b: Int) = a + b

    @LPFCP.ExposedFunction
    override fun subtract(a: Int, b: Int) = a - b
}

3. Start the Server (Server Code)

Use the embedded server helper to expose your service over HTTP:

fun main() {
    val calculator = CalculatorImpl()
    lpfcpServer(processor = calculator, port = 8080)
        .start(wait = true)
}

4. Call from a Client (Client Code)

Obtain a client-side proxy and invoke methods as if they were local:

fun main() {
    val calculator: Calculator = LPFCP.getProcessor<Calculator>(
        "http://localhost:8080/lpfcp"
    )
    println(calculator.add(1, 2))       // -> 3
    println(calculator.subtract(5, 3))  // -> 2
}

Learn more

Examples

Check out the examples/ folder for a working example of the calculator app in Java & Kotlin.

Wiki

Check out https://likespro.gitbook.io/lpfcp-java to view guides to LPFCP Java library.

Documentation

Check out https://likespro.github.io/lpfcp-java/ to view auto generated documentation for the project by Dokka (similar to Javadoc)

License

LPFCP Java is released under the Mozilla Public License Version 2.0.

About

Expose your functions to the network with just one annotation

Resources

License

Stars

Watchers

Forks

Packages