Coder Social home page Coder Social logo

kodein-cloud-functions's Introduction

Introduction

This project provides adapters to different cloud providers allowing developers to write Kotlin functions that are not tied to any specific cloud vendor.

Although it is highly inspired on the amazing Spring Cloud Function, this project is far from providing anything even close to the functionality provided by the Spring project. This is simply an idea that may fly with others one day

How to use

I took a lot of liberty on using Kodein as the DI framework for the project, many of the decisions I made may not be the best, and hopefuly someone will correct it via a PR :)

In order to use the project you must first import it on your pom:

<dependency>
    <groupId>io.igx.kotlin.cloud.functions</groupId>
    <artifactId>kodein-cloud-functions-aws-adapter</artifactId>
</dependency>

The project uses java ServiceLoader mechanism to find Kodein modules on the classpath. You need to create a class that implements io.igx.kotlin.cloud.functions.ModuleLoader such as

class SampleModuleLoader : ModuleLoader {
    override fun getModules(): List<Kodein.Module> {
        val module = Kodein.Module("samples") {
            bind<Function1<Foo, Bar>>(tag = "fooBar") with singleton { FooBar() } (1)
            bind(tag ="reqRes") from singleton { {r:Request -> Response(200)} } (2)
        }
        return listOf(module)
    }
}
  1. Binding a top level class such as class FooBar : (Foo) → (Bar) {

  2. Binding of a high level function, no type declared

And as with any ServiceLoader implementation you need to create a file named META-INF/services/io.igx.kotlin.cloud.functions.ModuleLoader with the name of all the ServiceLoader implementations you have.

That’s pretty much all it takes, no dependency on the cloud provider contract.

On AWS when deploying make sure you set the Handler to io.igx.kotlin.cloud.functions.aws.KodeinStreamHandler and that you set a FUNCTION_NAME environment variable to match the tag attribute of your bind

Next steps

  • Improve docs a lot

  • Better reflection handling

  • Azure, OpenWhisk support

kodein-cloud-functions's People

Contributors

viniciusccarvalho avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.