kbrw / ewebmachine Goto Github PK
View Code? Open in Web Editor NEWThe HTTP decision tree as a plug (full elixir rewriting of basho/webmachine with improvements)
License: MIT License
The HTTP decision tree as a plug (full elixir rewriting of basho/webmachine with improvements)
License: MIT License
So, I'm still not getting this. I want to be able to handle JSON and Form posts, so I've created something that looks like this
resource [] do
content_types_provided do: {[{'application/json', to_json}], _req, _ctx}
to_html do: "test page"
def to_json, do: "{"d":"test page"}"
end
This fails, though, with JSON unsupported. I've also tried implementing content_types_provided as a straight def, but still no luck. How am I supposed to implement WebMachine functions with eWebMachine?
Thanks,
Lee
🐌 🐌 🐌
Neat! I wonder if a to_template macro would be useful so that you can use Elixirs EEx to template the resource body?.... just a thought :-)
In some workflow, 'state' modification is lost, for instance:
dans la décision n11 (en mode `post_is_create: true` avec un handler de type `from_json`)
si le handler `from_json` modifie le `state` alors cette modification n'est pas visible dans le
handler `create_path` qui est pourtant bien exécuté après
I’m fairly new to elixir and newer still to erlang/otp. I’m very interested in using ewebmachine, but I’m having a hard time just getting to the starting line. I'm running elixir 0.14.2 on erlang 17.0 on Mac OSX 10.9.3.
Here’s what I’ve done so far in a test project.
mix new hyperweb --sup # project created no problem
added ewebmachine as a dependency in mix.exs
defp deps do
[{:ewebmachine, git: "https://github.com/awetzel/ewebmachine.git"}]
end
mix deps.get # gets meck, mochiweb, ibrowse, webmachine, ewebmachine
mix deps.compile # compiles without any problems
created a new WebTest module in the lib directory
defmodule WebTest do
use Ewebmachine
resource ['test'] do
to_html do: "Hello World!"
end
end
changed the guts of the project’s supervisor lib/hyperweb.ex to look like the example in the readme
defmodule Hyperweb do
use Supervisor.Behaviour
def start_link, do: :supervisor.start_link({:local,MODULE},MODULE,[])
def init([]) do
supervise([
supervisor(Ewebmachine.Sup,[[modules: [WebTest],port: 8080]]),
], strategy: :one_for_one)
end
end
ran iex -S mix # got a compilation error for the supervisor
== Compilation error on file lib/hyperweb.ex ==
** (CompileError) lib/hyperweb.ex:2: module Supervisor.Behaviour is not loaded and could not be found
(elixir) expanding macro: Kernel.use/1
lib/hyperweb.ex:2: Hyperweb (module)
(elixir) src/elixir.erl:163: :elixir.erl_eval/2
(elixir) src/elixir.erl:156: :elixir.eval_forms/4
(elixir) src/elixir_lexical.erl:17: :elixir_lexical.run/2
(elixir) lib/kernel/parallel_compiler.ex:93: anonymous fn/3 in Kernel.ParallelCompiler.spawn_compilers/8
looked at the elixir getting started guide to see that Supervisor.Behaviour is no longer a thing, so removed the ‘.Behaviour’ part of that directive.
ran iex -S mix # everything compiles, but it craps out trying to start up:
=INFO REPORT==== 8-Jul-2014::09:01:14 ===
application: hyperweb
exited: {bad_return,
{{'Elixir.Hyperweb',start,[normal,[]]},
{'EXIT',
{undef,
[{'Elixir.Hyperweb',start,[normal,[]],[]},
{application_master,start_it_old,4,
[{file,"application_master.erl"},
{line,272}]}]}}}}
type: temporary
** (Mix) Could not start application hyperweb: exited in: Hyperweb.start(:normal, [])
** (EXIT) an exception was raised:
** (UndefinedFunctionError) undefined function: Hyperweb.start/2
(hyperweb) Hyperweb.start(:normal, [])
(kernel) application_master.erl:272: :application_master.start_it_old/4
And this goes deeper in the stack that I have familiarity with. Any help would be greatly appreciated. Thanks!
When using 'resources' macro with recent version of Plug, got the following error:
(RuntimeError) no routes defined in module Bkfw.Http.Api using Plug.Router
I wrote a simple resource:
resource ['test'] do
allowed_methods do
['GET']
end
to_html do
"Hello"
end
end
When I try to GET it, this happens:
[{erlang,atom_to_list,["GET"],[]},
{webmachine_decision_core,'-decision/1-lc$^0/1-0-',1,
[{file,"src/webmachine_decision_core.erl"},
{line,178}]},
{webmachine_decision_core,decision,1,
[{file,"src/webmachine_decision_core.erl"},
{line,178}]},
{webmachine_decision_core,handle_request,2,
[{file,"src/webmachine_decision_core.erl"},
{line,33}]},
{webmachine_mochiweb,loop,2,[{file,"src/webmachine_mochiweb.erl"},{line,74}]},
{mochiweb_http,parse_headers,5,[{file,"src/mochiweb_http.erl"},{line,180}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]
Oh, I get it. It needs to be an atom, not a list-string like it is in the erlang version.
It'd be neat if you could provide a simple example of how to do CRUD in ewebmachine. Guessing the differences from the erlang version is kind of hard. Especially when the error messages are like this.
Would it be possible to add more informative errors? Or would it be on erlang webmachine to do that?
See #21
Repeated multiple times
warning: the variable "user_state" is unsafe as it has been set inside a case/cond/receive/if/&&/||. Please explicitly return the variable value instead. For example:
case int do
1 -> atom = :one
2 -> atom = :two
end
should be written as
atom =
case int do
1 -> :one
2 -> :two
end
Unsafe variable found at:
lib/core.ex:434
Hi awetzel,
So, I'm having issues with routes. I have a dummy module which looks like this:
defmodule WebMain do
use Ewebmachine
resource [] do
to_html do: "home page"
end
resource ["test"] do
to_html do: "test page"
end
end
Now, when run, I can go to:
and I see "home page". If, however, I go to:
I get a 404 not found error. Am I missing something obvious?
Thanks,
Lee
I'm a noob so this is probably easy ...
Elixir master
Erlang R16B02 (erts-5.10.3)
I'm running it in an umbrella app.
Thanks
==> webmachine (compile)
Compiled src/webmachine_resource.erl
Compiled src/wrq.erl
src/webmachine_decision_core.erl:715: crypto:md5/1 is deprecated and will be removed in in a future release; use crypto:hash/2
src/webmachine_decision_core.erl:719: crypto:md5_init/0 is deprecated and will be removed in in a future release; use crypto:hash_init/1
src/webmachine_decision_core.erl:725: crypto:md5_final/1 is deprecated and will be removed in in a future release; use crypto:hash_final/2
src/webmachine_decision_core.erl:725: crypto:md5_update/2 is deprecated and will be removed in in a future release; use crypto:hash_update/3
src/webmachine_decision_core.erl:727: crypto:md5_update/2 is deprecated and will be removed in in a future release; use crypto:hash_update/3
ERROR: compile failed while processing /home/ritchie/Projects/btcbingo/deps/webmachine: rebar_abort
** (Mix) Could not compile dependency webmachine, /home/ritchie/.mix/rebar command failed. If you want to recompile this dependency, please run: mix deps.compile webmachine
/wm_debug url is broken
I have a reproducible case when (especially after the first slowly processed request), the follow up requests fail and after a while I see this printed:
** (exit) exited in: GenServer.call(Ewebmachine.Log, {:update, #Function<3.54786035/1 in Ewebmachine.Log.put/1>}, 5000)
** (EXIT) time out
Thoughts?
This seem to happen regardless where there's an active EventStream and the only mediation found so far is disabling wm_debug completely.
A route with
content_types_accepted do: ["application/json": :from_json]
will respond 404 if the right content-type header is not provided.
Example for @jeanparpaillon :
On sa_user you have
resource "/user/:namespace/:id" do %{user_id: id, ns: namespace} after
allowed_methods do: ["GET","PUT","DELETE"]
content_types_provided do: ["application/json": :to_json]
content_types_accepted do: ["application/json": :from_json]
curl -X PUT -v \
{sa_user_URL}/user/psa-dfs/[email protected] \
-H 'content-type: application/json' \
-d '{"password":"azerty","email":"[email protected]"}'
will send a 204 back
When
curl -X PUT -v \
{sa_user_URL}/user/psa-dfs/[email protected] \
-d '{"password":"azerty","email":"[email protected]"}'
will send a 404 back
Hi,
So, I know this is a webmachine issue, but it seems to be configuration based within Elixir.
I want to bring up the wmtrace utility. I've checked I'm in a :dev environment and I've checked that {trace, '/tmp'} is returning on the resource init and that the wmtrace_resource method call is being made. I've also checked that the trace is creating files in /tmp. However, when I call
localhost:8080/debug
I get a 404 page as though the wmtrace_resource call was never made. I've physically made this call in iex, but this doesn't fix the issue.
Thanks,
Lee
See #21
warning: function Exception.exception/1 is undefined or private
Found at 3 locations:
lib/core.ex:277
lib/core.ex:278
lib/core.ex:427
$ mix dialyzer
Checking PLT...
[:compiler, :crypto, :elixir, :kernel, :logger, :mime, :plug, :stdlib]
PLT is up to date!
Starting Dialyzer
dialyzer --no_check_plt --fullpath --plt /home/jean/BA_Projets/git/ewebmachine/_build/dev/dialyxir_erlang-19.2.1_elixir-1.3.3_deps-dev.plt /home/jean/BA_Projets/git/ewebmachine/_build/dev/lib/ewebmachine/ebin
Proceeding with analysis...
lib/core.ex:192: The pattern 'nil' can never match the type {binary(),binary(),map()}
lib/core.ex:224: Guard test 'or'('false','false') can never succeed
lib/core.ex:238: Guard test 'or'('false','false') can never succeed
lib/core.ex:255: Guard test 'or'('false','false') can never succeed
lib/core.ex:269: Guard test 'or'('false','false') can never succeed
lib/core.ex:344: The test {{integer(),integer(),integer()},{integer(),integer(),integer()}} == 'bad_date' can never evaluate to 'true'
lib/core.ex:478: The test {{integer(),integer(),integer()},{integer(),integer(),integer()}} == 'bad_date' can never evaluate to 'true'
lib/core.ex:791: Guard test 'or'('false','false') can never succeed
lib/plugs.ex:212: Invalid type specification for function 'Elixir.Ewebmachine.Plug.ErrorAsException':exception/1. The success typing is (#{'status':=_, _=>_}) -> #{'__exception__':='true', '__struct__':='Elixir.Ewebmachine.Plug.ErrorAsException', 'message':=bitstring(), 'plug_status':=_}
Unknown functions:
httpd_util:convert_request_date/1
httpd_util:day/1
httpd_util:month/1
done in 0m2.63s
done (warnings were emitted)
See #21
Repeated multiple times
warning: the variable "conn" is unsafe as it has been set inside a case/cond/receive/if/&&/||. Please explicitly return the variable value instead. For example:
case int do
1 -> atom = :one
2 -> atom = :two
end
should be written as
atom =
case int do
1 -> :one
2 -> :two
end
Unsafe variable found at:
lib/core.ex:434
Timex is a great datetime library: https://hex.pm/packages/timex
Could known_content_type default handler could use content_types_accepted callback ?
Actually, it answers true, but accept_helper function raises exception if acceptor callback is not present
elixir 1.3 deprecates some languages features used in ewebmachine, producing a lot of warnings
While plug/cowboy employ a convertion of a lower case for response header, ewebmachine uses capitalized ones. Any thoughts on adjusting this or possibly making configurable?
Apologies if this ends up being a dumb user error on my part, but when using ewebmachine as a dependency and attempting to compile, I get the following error:
$ mix deps.compile ewebmachine
==> ewebmachine
Compiled lib/ewebmachine.ex
lib/conn_logger.ex:43: warning: erlang:now/0: Deprecated BIF. See the "Time and Time Correction in Erlang" chapter of the ERTS User's Guide for more information.
Compiled lib/conn_logger.ex
Compiled lib/builders.ex
Compiled lib/handlers.ex
== Compilation error on file lib/plugs.ex ==
** (CompileError) templates/log_list.html.eex:15: function full_path/1 undefined
(stdlib) lists.erl:1337: :lists.foreach/2
(stdlib) erl_eval.erl:669: :erl_eval.do_apply/6
(stdlib) erl_eval.erl:122: :erl_eval.exprs/5
mix.exs deps for reference:
defp deps do
[
{:ewebmachine, "2.0.8"},
{:cowboy, "1.0.2"}
]
end
When I clone the ewebmachine repo locally and build it there are no errors, so I'm not sure what my problem is.
Elixir 1.0.5 and erlang 18.0.2.
Thanks,
Joel
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.