erlangnitrogen

Determine HTTP method type


I'm trying to determine the HTTP method (GET, POST) send to an erlang module in nitrogen. I've added nitrogen as a dependency via rebar.

I'm attempting to do this via the wf_context:request_method/0 from nitrogen_core. However I can't figure out how to import/include the method. I've tried using import/2, include and include_lib. None have worked. Simply invoking the method with wf_context:request_method() doesn't work aswell.

The error I keep getting:

{error,error,undef,[{wf_context,request_method,[],[]}, ...]}


Solution

  • Adding Nitrogen as a dependency requires a few more steps than just adding the base nitrogen application as a dependency, since each request requires a setup and teardown, and the Nitrogen server need to be started.

    The simplest way to add Nitrogen to an existing application is to use the provided embed script.

    You would do this as follows:

    1. Make a temporary directory and clone nitrogen into it:

      $ cd /tmp $ git clone git://github.com/nitrogen/nitrogen

    2. Change to your project's directory, and invoke the embed script

    $ cd /path/to/my/project $ /tmp/nitrogen/embed

    Follow the directions on the prompt. Unless you have a reason otherwise, the defaults are usually just fine.

    I have a blog post I wrote about this a while back: http://sigma-star.com/blog/post/embedding-nitrogen

    Once you've properly added nitrogen to your application, and the nitrogen process is started, you should be good to go, you will no longer undef errors for Nitrogen standard functions.