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)
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.
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.
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.
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.
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.
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.
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).
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.
struct WelcomeController <: ApplicationController
render(JSON, "Hello World")
json = JSON.parse(String(c.conn.request.body))
get("/", WelcomeController, index)
post("/resource/process", WelcomeController, process_resource)
Base.JLOptions().isinteractive == 0 && wait()