Christian's email:
>>>
Hello. I was looking through ewgi to see if I wanted to implement that
callback for ifastcgi (http://github.com/noss/ifastcgi/tree/master). I
postponed doing it because it seemed so straight forward and simple. But
I do think some standard callback interface should be in place.
Something that I do not like about ewgi is that the return values are
specified in the actual values. Something I added to iserve, that
Torbjörn Törnkvist wrote, was to use functions instead of the direct
values.
> From http://github.com/noss/iserve/tree/master/test/iserve_test.erl:
> iserve_request(_C, Req) ->
> error_logger:info_report(
> lists:zip(record_info(fields, req), tl(tuple_to_list(Req)))),
>
> Headers = [{'Content-Type', "text/html"}],
> iserve:reply_ok(Headers, body_ok()).
There are things I like better about this approach:
* using iserve:reply_ok/2 instead of an explicit return value
something like {ok, 200, Headers, Body}
means that I can change the shape of the return term without needing
to change code in callbacks.
* the concept hides more implementation details, such as the
iserve:reply_redirect(Headers, URL) hiding the
specific header to add and the status code in http. "what i want,
not how i want it done". but still allowing you to do whatever you
want with iserve:reply_raw/3
* To me, dialyzer presents clearer results when checking types passed
to functions than types of returned values.
* a badarg will show the actual module iserve:reply_ok was called from
in the stacktrace.
PS
There are a bunch of callback signatures for http requests now.
Mochiweb seem to be the de-facto standard, abusing parameterized
modules.
<<<
End Christian's email
IMHO adding some apis for common responses would be a good idea. What do
you think?
Cheers,
filippo
I hope I'm understanding your question correctly. The main reason is
so that EWGI applications can be chained together easily. A trivial
example:
CtxResult = app3(app2(app1(Ctx)))
The application that you are writing may not return the final value.
The return values are well-defined, not opaque types.
Best,
Hunter
We have to be careful to separate the EWGI specification and the
sample "API" as given by the ewgi Google code project. The
specification is merely a document which gives implementors a set of
rules to follow. It does not say anything about the API (except
perhaps for "advice") specifically.
> Personally I would still like to argue for transparent case though, where
> you do not hide information, even though this may cause problems for
> implementors when upgrading the specification.
> ...
I am 100% in agreement here. The more transparent the specification
is, the more flexible the implementations can be. I do not expect web
application developers to even really bother with the EWGI spec as
they will be using it through one or more APIs.
> Even if not in the spec. I guess that implementing EWGI API the way
> Christian propose is far the best for most cases, but for the reasons above
> I am a bit reluctant to go all the way - not saying it could absolutely not
> be in the spec. (i.e. I am relaxing my "should" statement, to a "ought to"
> :-).
I think Christian's proposal is a great idea for the API, but we just
have to be careful not to mix the API and the specification too
closely. Do we have any more specific suggestions about changes to
the ewgi_api module?
Best,
Hunter