Implement a REST server in Julia?


#1

I would like to build a REST API for a Julia code. I am currently evaluating whether I use also Julia to implement the REST server or if I use another language (e.g. Python) for the server part.

These are the package that I have seen so far:

  • HTTP.Servers (from HTTP.jl)
  • HttpServer.jl
  • Genie.jl
  • Mux.jl

Do you have any recommendations?

Personally, I like the style of the python library Flask. The julia code can take a long-time to run (hours). So the client will need to check periodically if the calculation is done. But it is important that the calculation should not block any new request.

Thanks for your input!


#2

I’m in the same boat. I’m currently setting up demos using the new HTTP.jl but it’s slow going (there’s not a lot of high-level documentation for it at the moment). In the short term it’s probably easier to build the API in Flask or similar and spawn Julia worker processes.


#3

If you just need a couple of endpoints just to expose computations to the outer world, I’d go with HttpServer.jl - it’s very basic and low-level, but worked well for me a couple of times. If you need more complex routing, Mux.jl should a better fit. Genie.jl is more like Django in Python world: it’s server + ORM + templates, etc., for me it turned to be an overkill. No idea what HTTP.Server is about, so you’d need to figure it out yourself.


#4

I recently updated Pages.jl to use the new / improved HTTP.jl. It might be something to consider for APIs (it’s what I made it for) and I’m happy to help out if you have questions.


#5

We use JuliaWebAPI quite extensively to build REST servers. It is built on top of HTTPServer and Mux, and makes it easy to expose any julia function via a JSON based interface. For example, all of Juliabox’s internal APIs are built using this package. It is quite flexible, and extensible to other transports and message formats, if you need something other than HTTP and JSON respectively.


#6

https://github.com/amellnik/Joseki.jl is an example of how you can make simple APIs with just HTTP.jl. In your case it’s probably easier to make the API in whatever to write the jobs to redis or similar and report on progress, and separately have a julia worker that processes them.


#7

Although Mux.jl works fine for my latest project it seems like overkill since all I have to do is serve a static web page and respond to simple POST requests. So just yesterday I was wishing for more examples of doing simple stuff with HTTP.jl. Apparently I just willed this into existence. :slight_smile:

Also, I just have to ask: kyu or dan?


#8

I peaked around 6 kyu on kgs, and while I haven’t played seriously in a decade I got excited about the new AlphaGo joseki. I’ll add in an example of serving static content soon (although in my use cases I would always do that separately).


#9

amellnik: thank you very much for sharing the code example which is very helpful to me!

I will also have a look to Pages.jl and JuliaWebAPI. Thank you all for your insights.


#10

What were your conclusions regarding implementating restful API s in Julia? I’m currently doing all of this in flask but Would love to switch to Julia.


#11

take one more example for RESTful API in Bukdu.jl


#12

Hi Mike, I ended up using HTTP.jl:

HTTP.jl is quite flexible and already quite complete for my needs. The syntax/API is not as short as in Flask but the code overhead is acceptable. Maybe registering function could be simplified by using do functions (like sinatra http://sinatrarb.com/intro.html ) or macros.


#13

Bukdu looks indeed quite nice and concise. Thank you for sharing it!