dummy-link

WebFuncs

Expose plain Julia functions through HTTP

Readme

WebFuncs

Instantly turn custom functions into HTTP endpoints

Build Status

Coverage Status

codecov.io

Usage

With Dict input

import WebFuncs
m = WebFuncs.Mapping()
f = input -> input["a"] * 2
WebFuncs.expose!(m,f)
# 35729b69-43e6-470d-86c2-ee00f1222a4d
WebFuncs.run(m, 8080)
# Listening on 0.0.0.0:8080...

In another terminal:

$ curl -X POST http://localhost:8080/35729b69-43e6-470d-86c2-ee00f1222a4d -d "{\"a\": 42}"
{"result":84}

With a custom struct

import WebFuncs

struct Message
    info::String
    code::Int
end

function process(m::Message)
    if m.code == 42
        return "The answer"
    end
    return m.info
end

m = WebFuncs.Mapping()
# Giving the expected input type to convert incoming JSON data
WebFuncs.expose!(m,process,Message)
# 4fbff4f3-27b4-4e86-b02f-a82f0aba3eda
WebFuncs.run(m, 8080)

On the client bash:

$ curl -X POST http://localhost:8080/b5fbeef2-49c1-46bd-a5d5-7b9307d686e1 -d "{\"info\": \"toto\",\"code\": 41}"
{"result":"toto"}

$ curl -X POST http://localhost:8080/b5fbeef2-49c1-46bd-a5d5-7b9307d686e1 -d "{\"info\": \"toto\",\"code\": 42}"
{"result":"The answer"}

Structure

The main object is Mapping, associating a unique identifier (UUID) to a function. When launching the server, each function is exposed at host/function_id.

When adding a function to the mapping, its input type has to be provided, this input type has to be convertible from a JSON payload (either a Dict{String,T} or a struct). The endpoint converts the body to this Input format, passes it to the function and returns the output wrapped in a Dict at the "result" key.

Status and development

Early, feedback is welcome.
Features to come: improved type safety and parsing, other data formats as input.

First Commit

11/21/2017

Last Touched

over 1 year ago

Commits

23 commits

Used By: