# RESTful web services

**URL:** <https://discourse.julialang.org/t/restful-web-services/10046>\
**Category:** Web Stack\
**Created:** [March 29, 2018, 5:26am UTC](https://discourse.julialang.org/t/restful-web-services/10046 "2018-03-29T05:26:12Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [March 29, 2018, 5:26am UTC](https://discourse.julialang.org/t/restful-web-services/10046/1 "2018-03-29T05:26:12Z")

</div>

What package(s) may I use to build [RESTful](https://en.wikipedia.org/wiki/Representational_state_transfer) web services? Is there any tutorial around?

---

<div class="post-metadata">

**Author:** ![wookyoung](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wookyoung/32/157_2.png) [@wookyoung](https://discourse.julialang.org/u/wookyoung)\
**Post date:** [March 29, 2018, 1:30pm UTC](https://discourse.julialang.org/t/restful-web-services/10046/2 "2018-03-29T13:30:37Z")

</div>

If you are using Julia 0.7-DEV, you can run following sample.  
[https://github.com/wookay/Bukdu.jl/blob/sevenstars/examples/api/endpoint.jl](https://github.com/wookay/Bukdu.jl/blob/sevenstars/examples/api/endpoint.jl)

Required packages are HTTP.jl and Bukdu.jl:  
[https://github.com/wookay/Bukdu.jl/tree/sevenstars](https://github.com/wookay/Bukdu.jl/tree/sevenstars)

it just provide very basic stuff.  
any issue are welcome. thanks.

---

<div class="post-metadata">

**Author:** ![amellnik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amellnik/32/137_2.png) [@amellnik](https://discourse.julialang.org/u/amellnik)\
**Post date:** [March 29, 2018, 4:53pm UTC](https://discourse.julialang.org/t/restful-web-services/10046/3 "2018-03-29T16:53:28Z")

</div>

You can also build REST or other types of APIs directly with HTTP.jl. Once example of how to do this is [Joseki](https://github.com/amellnik/Joseki.jl). I think you can also do the same with @anon67531922’s [Pages](https://github.com/EricForgy/Pages.jl). In the past people did this with Mux but I wouldn’t recommend it going forward.

---

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [March 29, 2018, 6:47pm UTC](https://discourse.julialang.org/t/restful-web-services/10046/4 "2018-03-29T18:47:55Z")

</div>

What problems do you see with Mux? It would still be the first package I’d generally reach for if I were to build a web server thingy. Is it just the fact that it seems unmaintained at the moment?

---

<div class="post-metadata">

**Author:** ![amellnik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amellnik/32/137_2.png) [@amellnik](https://discourse.julialang.org/u/amellnik)\
**Post date:** [March 29, 2018, 8:30pm UTC](https://discourse.julialang.org/t/restful-web-services/10046/5 "2018-03-29T20:30:15Z")

</div>

I think the main issue is that it’s unmaintained, and most of the web ecosystem is moving towards the new HTTP.jl which provides a lot of the functionality that’s built into Mux.

The approach that Mux takes is also not one that I prefer. It works really well for people who want to spin up a basic webserver on their system, but lots of common tasks require mucking around in the Mux internals. For example, take a look at the [DiffEqOnline API](https://github.com/JuliaDiffEq/DiffEqOnlineServer/blob/master/api/mux_server.jl). @ChrisRackauckas and I needed to add CORS headers to all the responses which ended up being quite messy (although maybe there’s a better way to do it in Mux). We also needed custom error handling which required similar mucking around. I prefer the approach that Express takes – you construct a server by creating a middleware stack and adding routes from the ground up.

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [March 29, 2018, 8:56pm UTC](https://discourse.julialang.org/t/restful-web-services/10046/6 "2018-03-29T20:56:12Z")

</div>

Thanks for all the ideas. Now I have a lot to play with 🙂

I imagine that we’re not very mature in this area yet. A simple microservices framework similar to Python Flask would be great.

Alternatively, I also thought about exposing API’s via ZMQ and do the web tier in other languages but it would be much nicer to work in the same environment.

---

<div class="post-metadata">

**Author:** ![avik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avik/32/17_2.png) [@avik](https://discourse.julialang.org/u/avik)\
**Post date:** [March 29, 2018, 11:50pm UTC](https://discourse.julialang.org/t/restful-web-services/10046/7 "2018-03-29T23:50:11Z")

</div>

While it’s approach may not be for universally liked, Mux is very much _not_ unmaintained. There are many production servers running on Mux.

Every time this question comes up, I suggest [JuliaWebAPI.jl](https://github.com/JuliaWeb/JuliaWebAPI.jl) (so I’m clearly biased), but IMO nothing comes close to the easy and flexibility of this package to deploy REST services. It is built on top of Mux, which is built on top of `HTTPServer.jl`

Regards

Avik

---

<div class="post-metadata">

**Author:** ![anon67531922](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@anon67531922](https://discourse.julialang.org/u/anon67531922)\
**Post date:** [March 30, 2018, 12:08am UTC](https://discourse.julialang.org/t/restful-web-services/10046/8 "2018-03-30T00:08:19Z")

</div>

> nothing comes close to the easy and flexibility of this package to deploy REST services.

Them are fightin’ words! 🤠

Hehe. Every time this subject comes up, you recommend JuliaWebAPI.jl (for obvious reasons) and I recommend Pages.jl (for obvious reasons). Pages.jl has also been deployed to Azure for production purposes and will be used more heavily soon, so I appreciate eyes looking at it to help make it better 🙂

Although I’m sure JuliaWebAPI.jl is built on more solid web best practices, I think it is a bit too much to say it is the easiest. I tend to make every mistake in the book, which makes me a good teacher (because I can relate to suffering students 😅) and Pages.jl was built to be simple.

```julia
julia> using Pages; @async Pages.start()
Listening on 0.0.0.0:8000...
julia> Endpoint("/hello") do request::Request
       "Hello world"
       end
Endpoint created at /hello.

```

(Note: You can add `Endpoint`s any time, even after the server is started.)

One thing I like about this is you can get started without knowing anything about web development. You don’t even need to know the difference between `get` and `post`. The syntax is pretty self explanatory I think.

As a bonus, there is built in WebSocket functionality including `callback`s so you can have Julia and JavaScript talking to each other.

Check out the Plotly example. You can send plots from Julia to the browser in real-time from the REPL (with no page reloading). I’m hoping to add a lot more interactive plotting capability.

I need to tag a new version, so recommend `Pkg.checkout("Pages")` to get the master branch.

In any case, I am happy to see interest in web development and Julia. The more we work together, the better for everyone. Bukdu.jl looks cool and everyone should keep an eye on Charlotte.jl. That is a very exciting project. And for more serious web backends, in addition to JuliaWebAPI.jl, you should also check out Genie.jl.

Good luck! 😊

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [March 30, 2018, 6:43am UTC](https://discourse.julialang.org/t/restful-web-services/10046/9 "2018-03-30T06:43:31Z")

</div>

No worries, guys. I’m trying both and will submit some feedbacks to your Github repo.

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [April 1, 2018, 2:44am UTC](https://discourse.julialang.org/t/restful-web-services/10046/10 "2018-04-01T02:44:01Z")

</div>

Zero commits in the last 14 months + 8 open pull requests (for Mux.jl) doesn’t exactly scream maintained. Just sayin’ 😉

---

<div class="post-metadata">

**Author:** ![avik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avik/32/17_2.png) [@avik](https://discourse.julialang.org/u/avik)\
**Post date:** [April 1, 2018, 3:50pm UTC](https://discourse.julialang.org/t/restful-web-services/10046/11 "2018-04-01T15:50:11Z")

</div>

I think that’s is unfair. As I’ve said before, many production services depend on Mux, including Juliabox, used daily by thousands of users. If that’s not a sign of a mature library, I don’t know what is.

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [April 1, 2018, 7:41pm UTC](https://discourse.julialang.org/t/restful-web-services/10046/12 "2018-04-01T19:41:02Z")

</div>

I don’t think anyone’s questioned whether Mux.jl is mature or not widely used; the original question was what package to use for restful web services. Between a package that hasn’t been actively developed in a long time (Mux.jl) and a package that provides similar functionality _and_ is actively developed/maintained (HTTP.jl), I’m just saying I know what I’d target if I needed to setup a restful web service. HTTP.jl is already 0.7/1.0 ready and provides a much cleaner middleware layering stack for extensible servers.

---

<div class="post-metadata">

**Author:** ![samoconnor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/samoconnor/32/1802_2.png) [@samoconnor](https://discourse.julialang.org/u/samoconnor)\
**Post date:** [April 2, 2018, 2:27am UTC](https://discourse.julialang.org/t/restful-web-services/10046/13 "2018-04-02T02:27:04Z")

</div>

A word of caution to the OP:  
As the README.md for HTTP.jl says “The package is new and not yet tested in production systems.”.  
If you need something field-proven right now. HTTP.jl is not it.  
If you’re aiming to deploy a production system after the Julia 1.0 release, HTTP.jl is certainly under active development and heading towards being stable soon after the Julia 1.0 release.  
If you are willing to take a leap and try HTTP.jl now, that’s great!, and either @quinnj or I will try to help with any issues you encounter.

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [April 2, 2018, 2:33am UTC](https://discourse.julialang.org/t/restful-web-services/10046/14 "2018-04-02T02:33:18Z")

</div>

We should also update the docs, since there _is_ at least a handful of cases where HTTP.jl is being used in production (that I’m aware of at least).

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [April 3, 2018, 7:53am UTC](https://discourse.julialang.org/t/restful-web-services/10046/15 "2018-04-03T07:53:45Z")

</div>

@samoconnor & @quinnj - thanks for offering help.

May I also suggest improving the docs with complete examples about how to build a web service properly?

The README file has trivial examples with `HTTP.listen()` but I would want to know how to use the router or handler, how to create a filter and pass information from one to the next, how to start/stop the server, etc. I don’t think I’m the only one 🙂

---

<div class="post-metadata">

**Author:** ![macroscian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/macroscian/32/5790_2.png) [@macroscian](https://discourse.julialang.org/u/macroscian)\
**Post date:** [October 19, 2018, 1:43pm UTC](https://discourse.julialang.org/t/restful-web-services/10046/16 "2018-10-19T13:43:28Z")

</div>

I’ve used Pages.jl to run a tie a Julia simulation into a web front-end that allows the user to change the parameters and visualise the results - it’s going great so far (thanks Eric!). I’d like to send a progress report back to the user, and I just can’t get my head around Pages’ code for this. I merely want to send a bit of text back from a loop within Julia that has been triggered by a POST endpoint (and only to the browser that submitted the POST). I can’t figure out if I need the Pages.js functionality - it seems overkill and I don’t really understand it yet. There’s a bit in the examples/blank.html page that seems ideal, but when I try to run that example I get “Firefox can’t establish a connection to the server at ws://localhost:8000/examples/blank” - and foolishly I can’t understand how the simulation will know an ‘id’ to send the message to anyway.  
Sorry for the basic question (I’m no web developer, obviously!) - any help greatly appreciated.  
-Gavin

---

<div class="post-metadata">

**Author:** ![anon67531922](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@anon67531922](https://discourse.julialang.org/u/anon67531922)\
**Post date:** [October 19, 2018, 1:55pm UTC](https://discourse.julialang.org/t/restful-web-services/10046/17 "2018-10-19T13:55:13Z")

</div>

Hi @macroscian 👋

I’m glad to hear you’ve made some progress using Pages.jl and similarly sorry you’re having some difficulties. Do you mind opening an issue on Github and we can sort it over there? 😊

Here is the link to submit a new issue: [https://github.com/EricForgy/Pages.jl/issues](https://github.com/EricForgy/Pages.jl/issues)

---

<div class="post-metadata">

**Author:** ![anon67531922](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@anon67531922](https://discourse.julialang.org/u/anon67531922)\
**Post date:** [October 20, 2018, 3:21pm UTC](https://discourse.julialang.org/t/restful-web-services/10046/18 "2018-10-20T15:21:43Z")

</div>

If anyone is interested, here is the issue: [Websocket help · Issue #20 · EricForgy/Pages.jl · GitHub](https://github.com/EricForgy/Pages.jl/issues/20)

I simply exposed the client id as `Pages.id` accessable from JS so you can include that in your POST and use `Pages.message` from the Julia side with the client id 😊

---

<div class="post-metadata">

**Author:** ![macroscian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/macroscian/32/5790_2.png) [@macroscian](https://discourse.julialang.org/u/macroscian)\
**Post date:** [March 9, 2020, 10:38am UTC](https://discourse.julialang.org/t/restful-web-services/10046/19 "2020-03-09T10:38:58Z")

</div>

Hi @anon67531922 just to let you know that the paper we used your package in has eventually been published, and you’re duly acknowledged:  
[https://www.cell.com/cell/fulltext/S0092-8674(20)30153-7](https://www.cell.com/cell/fulltext/S0092-8674(20)30153-7)  
Thanks for your help on this.
