[ANN] Mongoose.jl - Build simple web servers

Hi there,

I just want to share this new package Mongoose.jl I developed as a personal project to dig in into Julia, it can be used to build simple web apps. It is build on top of mongoose c library.

Developing an API rest is a simple as:

using Mongoose

function greet(conn; kwargs...)
    mg_json_reply(conn, 200, "{\"message\":\"Hello World from Julia!\"}")
end

mg_register!("get", "/hello", greet)

mg_serve!()
# mg_shutdown!()

It is currently added in web frameworks benchmark.

I hope it helps someone and push Julia (at least a little) to be widely adopted for web development.

9 Likes

I love “Hello, world.” Tiny bit of friction. Where does it expect to put the favicon.ico?

Why you prefix all functions with mg_ which to me is very ugly. I’d like to mark those public API using the public keyword instead of export, and if in case of confilicts, use import Mongoose as mg and simply do mg.serve!(), etc.

3 Likes

The very mature HTTP.jl package can also make simple HTTP servers in few lines of code, e.g.:

using HTTP
HTTP.serve() do request
    HTTP.Response(200, "Welcome to my server")
end

What advantages does Mongoose.jl have?

2 Likes

I would guess that the names just match those used in the C library.

Very nice work!

1 Like

Correct, as @jd-foster mentioned I tried to keep the same naming style as the C library has. I hesitated to add the mg prefix but I did it to avoid collisions. Naming is hard.

I think a solution could be to use alias with public keyword for those exported functions (public serve! = mg_serve!)

Yes, I agree and it doesn’t try to replace it, I just wanted to offer another alternative in the Julia world.

Personally I have been using Oxygen.jl (based on HTTP.jl) to deploy some models into production and I truly recommend it.

Regarding the advantages:

  • For very simple endpoints it has better performance
  • It doesn´t have dependencies just Mongoose_jll
  • It is way simpler than HTTP.jl
5 Likes