[erlang-questions] Thoughts on EHE - the PHP killer

Tim Watson watson.timothy@REDACTED
Sun Feb 19 15:17:19 CET 2012


On 19 February 2012 03:39, Steve Vinoski <vinoski@REDACTED> wrote:
> To paraphrase:
>
> .yaws file: sprinkle a little Erlang into your HTML
> appmod: sprinkle a little HTML/XML/JSON/whatever into your Erlang
>
> An appmod is like a servlet, I suppose. It's code that handles
> requests made to a configured portion of the server URI space (the
> path can be "/" to handle all requests to that server), and can do
> pretty much anything it needs to in order to fulfill each request.
>
> In my own development work with yaws, I use appmods almost exclusively
> because they're totally flexible.
>
> --steve

Thanks steve, that was the understand I had come to from looking at
what's on the site. What I haven't quite figured out is how the stuff
in an out/1 function gets interspersed with the surrounding HTML and
what happens when there are multiple out/1 definitions and so on. But
frankly, I'm *much* more likely to use appmods anyway, as like you say
they're a lot more like a servlet.

I think I might go away and wire up some
https://github.com/hyperthunk/annotations with so that you can write a
handler that takes parts of the request URL and other bits from the
Arg record declaratively. I think it will be quite easy to write an
appmod that uses this to reroute the request, giving me something that
looks a bit like this:

-controller({"/accounts/{account_type}", 'POST', include_body}).
get_account(AccountType, PostBody, YawsArg) ->
    ....

-controller({"/accounts/{account_type}/{account_number}/", 'GET'}).
get_account(AccountType, AccountNum, YawsArg) ->
    ....

Obviously this isn't as cool as a webmachine-a-like running on YAWS,
but I *think* I can make it work quite easily and it makes for more
convenient mapping of URLs to controller/handler module + function.

Next question I have is, how hard would it be to do something like a
servlet filter in YAWS? I could do this quite well using annotations -
that's how ErlangWeb does it, albeit with macros instead - but is that
the best way? It would look something like this (and is quite easy to
implement using annotations):

-secured({auth_provider, oauth}).
-controller({"/accounts/{account_type}/{account_number}/", 'GET'}).
get_account(AccountType, AccountNum, YawsArg) -> ....


Is there something else in YAWS like appmod that'll do a filter chain,
or am I better off using annotations?

Cheers,

Tim



More information about the erlang-questions mailing list