How to implement GET in httpd server? error: Not Implemented

Hi,
I am trying out erlang http server. I am getting below error. How can I implement GET

Not Implemented
GET to /esi (HTTP/1.1) not supported.

Below is the code to start the server, esi module is in the same directory.

start_esi()->
    inets:start(),
    inets:start(httpd, [
        {port, 80}, 
        {server_name, "httpd_test"}, 
        {server_root, "/laragon/www/erlangtutorials/http"}, 
        {document_root, "/laragon/www/erlangtutorials/http/public"}, % Get current path
        {modules, [mod_esi]}, 
        {erl_script_alias, {"/esi", [esi]}}
        ]).```
5 Likes

FWIW, I’m not sure anyone ever uses httpd, though surely someone has to as it’s still in there :slight_smile:

If you’re looking for a solid web server in erlang checkout GitHub - elli-lib/elli: Simple, robust and performant Erlang web server or GitHub - ninenines/cowboy: Small, fast, modern HTTP server for Erlang/OTP.

That said, I think this should help you : otp/httpd_example.erl at master · erlang/otp · GitHub

Good luck.

3 Likes

My guess would be that you are not using the correct path when you call your http server.

The path is determined like this: localhost:8081/ErlScriptAlias/Module/Function
where ErlScriptAlias is as configured in your httpd (/esi), Module is the esi callback module (esi) and Function is the function inside the callback module (hello).

A working example to illustrate just the esi.

% $ cat esi.erl
-module(esi).
-export([hello/3]).

hello(SessId, _Env, _Input) ->
    mod_esi:deliver(SessId, ["Hello, World"]).
% cat starter.erl
-module(starter).
-export([start_esi/0]).

start_esi() ->
    inets:start(),
    inets:start(httpd, [
                        {port, 8081},
                        {server_name, "httpd_test"},
                        {server_root, "."},
                        {document_root, "."}, % Get current path
                        {modules, [mod_esi]},
                        {erl_script_alias, {"/esi", [esi]}}
                       ]).

Then:

$ erlc *.erl
$ erl
Erlang/OTP 24 [erts-12.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit]

Eshell V12.0  (abort with ^G)
1> starter:start_esi().
{ok,<0.91.0>}

And finally to call the esi script:

$ curl localhost:8081/esi/esi/hello
Hello, World
# Or this works too:
$ curl localhost:8081/esi/esi:hello
Hello, World
3 Likes

Hi @starbelly ,

Thank you for the info.

What are the limitations of httpd? I wonder what makes people not using it.

4 Likes

Thank you @cmkarlsson, this worked.

4 Likes

I would speculate that performance is probably one big reason. That said, personally I would not like to see it used as I think it should be removed from OTP, there’s plenty of a great web servers that live in the erlang ecosystem and removing it would shrink OTP, less to maintain.

2 Likes