Skip to content

Latest commit

 

History

History
282 lines (213 loc) · 11.4 KB

README.md

File metadata and controls

282 lines (213 loc) · 11.4 KB

elide: verb. to omit (a sound or syllable) when speaking. to join together; to merge.


Build codecov Reliability Rating Security Rating Maintainability Rating FOSSA Status Java 20 GraalVM Kotlin Kotlin/JS. IR supported ECMA OpenSSF Best Practices

Latest version: 1.0-v3-alpha5-b15


Elide is a cloud-first polyglot runtime for developing fast web applications. It aims to reduce the barriers between languages and improve performance of existing code, without forcing developers to abandon their favorite APIs and libraries.

Important

Elide is still in alpha, some features are not fully supported and others may fail on certain environments.

Using the runtime binaries

You can install the runtime by running:

curl -sSL --tlsv1.2 "dl.elide.dev/cli/install.sh" | bash -s -

After installation, you can run elide help or elide info to see more information.

Features

The Elide CLI supports JavaScript out of the box, and includes experimental support for Python, while more languages such as Ruby are planned for future releases.

Environment files

Elide provides .env files support at the runtime level, without the need for manual configuration or third-party packages. Environment variables from .env files will be picked up and injected into the application using a language-specific API (e.g. process.env in JavaScript).

Server engine

Let's see an example, the following JavaScript application configures a built-in HTTP server and adds a route handler with path variables:

// access the built-in HTTP server engine
const app = Elide.http

// register a route handler
app.router.handle("GET", "/hello/:name", (request, response, context) => {
  // respond using the captured path variables
  response.send(200, `Hello, ${context.params.name}`)
})

// configure the server binding options
app.config.port = 3000

// receive a callback when the server starts
app.config.onBind(() => {
  console.log(`Server listening at "http://localhost:${app.config.port}"! 🚀`)
})

// start the server
app.start()

The server can be started with:

> elide serve app.js
> elide 17:43:09.587 DEBUG Server listening at "http://localhost:3000"! 🚀

Important

The Elide HTTP intrinsics are under active development and provide only limited features. We are actively working to improve performance and support more use cases.

Planned features

The following features are currently planned or under construction:

  • Secret management: access secrets as environment variables visible only to your application, decouple your code from secret management SDKs and let the runtime handle that complexity for you.
  • Isolated I/O: use pre-packaged archives to provide read-only, sealed Virtual File Systems, allowing access to the host File System only where needed.
  • Built-in telemetry: managed, configurable integration with telemetry APIs.
  • Native distributions: build your app into a truly native binary using GraalVM's Native Image technology, ship optimized applications without including a runtime in your container.

Use with server frameworks

Elide integrates with Micronaut to provide Server-Side and Hybrid rendering options with very high performance, by running JavaScript code inside your JVM server:

// build.gradle.kts
implementation("dev.elide:elide-server:1.0-v3-alpha5-b15")

or if you use Groovy:

// build.gradle
implementation 'dev.elide:elide-server:1.0-v3-alpha5-b15'

See our samples to explore the features available when integrating with server frameworks, the following code for a server application uses React with Server-Side Rendering:

// server/App.kt

/** GET `/`: Controller for index page. */
@Controller class Index {
  // Serve an HTML page with isomorphic React SSR.
  @Get("/") fun index() = ssr {
    head {
      title { +"Hello, Elide!" }
      stylesheet("/styles/main.css")
      script("/scripts/ui.js", defer = true)
    }
    body {
      injectSSR()
    }
  }

  // Serve styles for the page.
  @Get("/styles/main.css") fun styles() = css {
    rule("body") {
      backgroundColor = Color("#bada55")
    }
    rule("strong") {
      fontFamily = "-apple-system, BlinkMacSystemFont, sans-serif"
    }
  }

  // Serve the built & embedded JavaScript.
  @Get("/scripts/ui.js") suspend fun js(request: HttpRequest<*>) = script(request) {
    module("scripts.ui")
  }
}

By evaluating the JavaScript code built using a Kotlin/JS browser app:

// client/main.kt

// React props for a component
external interface HelloProps: Props {
  var name: String
}

// React component which says hello
val HelloApp = FC<HelloProps> { props ->
  div {
    strong {
      +props.name
    }
  }
}

// Entrypoint for the browser
fun main() {
  hydrateRoot(
    document.getElementById("root"),
    Fragment.create() {
      HelloApp {
        name = "Elide"
      }
    }
  )
}

Note

More versatile integration with frameworks like Micronaut and Ktor is planned but not yet supported. The API and packages used for these integrations may change as we add more features.

Building a custom runtime

If you are building a JVM application that runs guest code in one of the languages supported by Elide, you can use the Runtime DSL to configure your own embedded polyglot engine:

implementation("dev.elide:elide-graalvm:1.0-v3-alpha5-b15")

or for Groovy scripts:

implementation 'dev.elide:elide-graalvm:1.0-v3-alpha5-b15'

The DSL is used internally by the Elide binaries and by the SSR packages and provides a simplified API to harness the power of the underlying GraalVM engine:

// configure and create a new engine
val engine = PolyglotEngine {
  // add support for the JavaScript language
  install(JavaScript) {
    // enable ESM support
    esm = true
    
    // include custom bindings into the engine, these
    // will be available as top level symbols
    bindings {
      put("version", "1.0.0")
    }
  }
}

// obtain a context to evaluate source code
val context = engine.acquire()

// evaluate guest JavaScript code
context.javascript("""
  console.log(`Hello from custom runtime v${version}`)
""")

Warning

The Elide Runtime DSL is intended for advanced use cases, and while we try not to break compatibility between releases, there are no guarantees.

Version compatibility

The following version matrix indicates tested support across tool and platform versions, including Java, Kotlin, GraalVM, Micronaut, and React.

Following this guide is recommended but optional. Depending on the style of development you're doing with Elide, you may not need some of these components:

Status Java Kotlin GraalVM Micronaut React Protobuf/gRPC
Status Java 20 1.9.20-Beta2 23.0.x 4.0.x 18.x 3.21.11/1.56.1
Status Java 20 1.9.10 23.0.x 3.10.x 18.x 3.21.11/1.56.1
Status Java 17 1.8.20 22.3.x 3.9.x 18.x 3.21.11/1.42.0
Status Java 11 1.7.22 22.3.x 3.5.x 18.x 3.20.1/1.46.0
Status Java 8-10 -- -- -- -- --

If you aren't using certain components on this list, for example, gRPC/Protobuf, you can ignore that column entirely.

Reports

Licensing

Elide itself is licensed under MIT as of November 2022. Dependencies are scanned for license compatibility; the report is available via FOSSA:

FOSSA Status

Coverage

Code coverage is continuously reported to Codecov and SonarCloud:

Coverage grid

Contributing

Issue reports and pull requests are welcome! See our contribution guidelines or join our discord community and let us know which features you would like to see implemented, or simply participate in the discussions to help shape the future of the project.