How to integrate Julia with a HTML web page - how to call a Julia function from an application running in a web browser

Viewed 187

we have a Julia language calculation engine we want to trigger on command from a HTML webpage.

How can I connect from this application to a Julia instance. Is it possible to connect to Julia via a REST service?

1 Answers

You just need to have Julia listening on a port for incoming requests and have it respond accordingly. You can use an HTTP package (like HTTP.jl) to easily set up a REST endpoint:

import HTTP
using Sockets
compute(req::HTTP.Request) = HTTP.Response(200, "hello world")
const SERVER = HTTP.Router()
HTTP.@register(SERVER, "GET", "/test", compute)
HTTP.serve(SERVER, ip"127.0.0.1", 12345)

Now accessing http://127.0.0.1:12345/test should show you a page with the string hello world on it.

There are many frameworks that build atop this basic paradigm.

Related