How to integrate Julia function into pre-existing web app?

I have absolutely no experience with web development stuff (I mostly just do backend stuff), so please forgive me if this is a naive question.

My company has a web application written in C#, and I’d like to have it utilize a function I’ve written in Julia that takes some inputs, retrieves data from a database, and does some calculations. I want this calculation done with Julia specifically because it’s faster than any other language I know (and these calculations require a fairly large amount of data/computations), and it’s readability should make it much easier to maintain/further develop.

What is the best way for me to integrate that Julia code into the application? Would I have to have Julia installed on the web server?

I honestly have very little idea how to make this happen, let alone what the best way to do it is.

Any advice is greatly appreciated!!

1 Like

I don’t know if there is a way for C# to call Julia function, but recently I have wrapped a function into a webservice with little effort using HTTP.jl. So any programming language with RESTful tools can utilize your Julia function.

using HTTP
function does_some_calculations(x)
    return y
function process_http_request(req::HTTP.Request)
    x = string(HTTP.playload(req))
    y = does_some_calculations(x)
    return HTTP.Response(200, y)
const RESTful_ROUTER = HTTP.Router()
HTTP.@register(RESTful_ROUTER, "POST", "/api/calculation/v1/post",  process_http_request)
HTTP.serve(RESTful_ROUTER, HTTP.Sockets.IPv4(""), 5000)

For this to work, I assume it requires Julia to be installed on the web server?

Not required, you can run this Julia code on another server and have your webserver proxy requests to this other server as needed. This is pretty trivial to do with standard webservers, and probably not too hard if you’re doing everything in C#.

1 Like

Could you please suggest how this was done ?
I am looking to trigger a Julia language calculation engine 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

Sure, just use HTTP.jl (or maybe Mux.jl) to set up your endpoints and you’re good to go.

Since you don’t need to utilize the HTTP protocol, simply TCP connections may support the connection between platforms. However, in this way you have to decode / encode commands and results using a format like JSON or XML (extra overhead).

Opening external Julia processes for each request is also high-weight operation and is not useful for this case.

Additionally, the package Genie is more than the HTTP protocol but like a web framework, can simply host your functions as web APIs.