# Create API endpoint to run arbitrary Julia code

**URL:** <https://discourse.julialang.org/t/create-api-endpoint-to-run-arbitrary-julia-code/92246>\
**Category:** Tooling\
**Created:** [December 28, 2022, 9:32pm UTC](https://discourse.julialang.org/t/create-api-endpoint-to-run-arbitrary-julia-code/92246 "2022-12-28T21:32:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flavio\_Barros](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/flavio_barros/32/45443_2.png) [@Flavio\_Barros](https://discourse.julialang.org/u/Flavio_Barros)\
**Post date:** [December 28, 2022, 9:32pm UTC](https://discourse.julialang.org/t/create-api-endpoint-to-run-arbitrary-julia-code/92246/1 "2022-12-28T21:32:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 28, 2022, 10:20pm UTC](https://discourse.julialang.org/t/create-api-endpoint-to-run-arbitrary-julia-code/92246/2 "2022-12-28T22:20:14Z")

</div>

> [@Flavio\_Barros](#):
>
> 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](https://jupyter-client.readthedocs.io/en/stable/messaging.html), it runs over [ZeroMQ](https://zeromq.org/), sends code via JSON, and receives multimedia results via JSON. The Julia backend is called [IJulia](https://github.com/JuliaLang/IJulia.jl), 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](https://github.com/IRkernel/IRkernel) 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](https://github.com/julia-vscode/LanguageServer.jl), which implements the Microsoft [Language Server Protocol](https://en.wikipedia.org/wiki/Language_Server_Protocol) and [JSON-RPC](https://en.wikipedia.org/wiki/JSON-RPC) via [JSONRPC.jl](https://github.com/julia-vscode/JSONRPC.jl) (which you could use directly instead of LanguageServer).

There is also [Genie.jl](https://github.com/GenieFramework/Genie.jl), which is a lower-level framework for developing web apps in Julia.

---

<div class="post-metadata">

**Author:** ![Flavio\_Barros](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/flavio_barros/32/45443_2.png) [@Flavio\_Barros](https://discourse.julialang.org/u/Flavio_Barros)\
**Post date:** [December 29, 2022, 7:35pm UTC](https://discourse.julialang.org/t/create-api-endpoint-to-run-arbitrary-julia-code/92246/3 "2022-12-29T19:35:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [December 29, 2022, 8:35pm UTC](https://discourse.julialang.org/t/create-api-endpoint-to-run-arbitrary-julia-code/92246/4 "2022-12-29T20:35:12Z")

</div>

Hey @Flavio_Barros , you may want to try out [Oxygen.jl](https://github.com/ndortega/Oxygen.jl) as well since it sounds like you are looking for something pretty lightweight

---

<div class="post-metadata">

**Author:** ![Flavio\_Barros](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/flavio_barros/32/45443_2.png) [@Flavio\_Barros](https://discourse.julialang.org/u/Flavio_Barros)\
**Post date:** [January 16, 2023, 6:05pm UTC](https://discourse.julialang.org/t/create-api-endpoint-to-run-arbitrary-julia-code/92246/5 "2023-01-16T18:05:22Z")

</div>

I have found [TinyRPC.jl](https://github.com/notinaboat/TinyRPC.jl), and I believe, from the examples, that this is exactly what I need.

---

<div class="post-metadata">

**Author:** ![DoktorMike](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/doktormike/32/2736_2.png) [@DoktorMike](https://discourse.julialang.org/u/DoktorMike)\
**Post date:** [January 16, 2023, 6:53pm UTC](https://discourse.julialang.org/t/create-api-endpoint-to-run-arbitrary-julia-code/92246/6 "2023-01-16T18:53:58Z")

</div>

Oxygen is really cool. I used it whenever i build RESTful API s in julia. 👍🏻
