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!!

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
end
function process_http_request(req::HTTP.Request)
    x = string(HTTP.playload(req))
    y = does_some_calculations(x)
    return HTTP.Response(200, y)
end
const RESTful_ROUTER = HTTP.Router()
HTTP.@register(RESTful_ROUTER, "POST", "/api/calculation/v1/post",  process_http_request)
HTTP.serve(RESTful_ROUTER, HTTP.Sockets.IPv4("127.0.0.1"), 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