Create API endpoint to run arbitrary Julia code

Hello, I’m learning Julia and didn’t find in my research a way to solve a problem: I need to create an API endpoint that receives Julia code, run it on the server and return the output as JSON for example. In R I use Rserver for something like this. In Julia what can be done?

Depends on what you need. You could use the Jupyter Messaging Protocol, it runs over ZeroMQ, sends code via JSON, and receives multimedia results via JSON. The Julia backend is called IJulia, and requires no Python — you just talk to it with ZMQ. Plus, once you implement this protocol you can also use it to talk to R and many other languages. However, the Jupyter protocol is mainly oriented towards UI front-ends — code results are sent as text (embedded in JSON), which you would have to parse if you want to turn it back into numbers.

You can also look into LanguageServer.jl, which implements the Microsoft Language Server Protocol and JSON-RPC via JSONRPC.jl (which you could use directly instead of LanguageServer).

There is also Genie.jl, which is a lower-level framework for developing web apps in Julia.

4 Likes

Thank you @stevengj! I just checked and I believe that LanguageServer.jl is too complex for something like that and maybe is overkill. But an instance of a jupyter server is more like wthat I am looking for. I didn’t know that I could use the jupyter server without the ui of notebooks and in the documetation is not clear to me how could I access the jupyter server directly.

With Genie.jl I am puzzled: I have used Django in the past and from my understanding with Genie.jl I could map an URL to a function, a Julia function in this case, and POST data por exemple. Lets say I mapped that URL and have posted and string that happens to be Julia code, How could I eval and get back the result with Julia itself?

Hey @Flavio_Barros , you may want to try out Oxygen.jl as well since it sounds like you are looking for something pretty lightweight

1 Like

I have found TinyRPC.jl, and I believe, from the examples, that this is exactly what I need.

1 Like

Oxygen is really cool. I used it whenever i build RESTful API s in julia. :+1:t2: