0

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,[],[]}, ...]}

1 Answers1

1

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.

chops
  • 2,572
  • 1
  • 16
  • 25
  • Thanks for the info. I had everything configured correctly. The problem was that i was using v2.2.2. in which the desired method wasn't yet implemented. The confusion arose from the fact that i was looking at the code from the master branch in github. Updating to {branch, master} fixed the problem. I'll accept your answer to "close" the question. – Nikolay Manolov Jan 26 '15 at 19:25
  • Gotcha! Thanks. Excellent! Version 2.3.0 will be released soon (one minor fix needs to be done then it's ready!), so having updated to master branch should not give you problems. – chops Jan 26 '15 at 20:42