开发者

REST service in Ejabberd; DELETE and PUT Method

I am using the request handlers found in ejabberd to build a REST service.

Is it possible to invoke the ejabberd request_handlers with a PUT and DELETE HTTP Method? If so how?

I have been able to invoke request_handlers with POST and GET HTTP Methods successfully but can't seem to be able to do the same with PUT or DELETE.

Every time I try to do a PUT or DELETE I get in return a "400 Bad Request"

I am using curl to do the testing

curl -i -X <METHOD>  <URL>

for GET, PUT and DELETE, and

curl -i -X <METHOD>  <URL> -d <POSTBody>

for POST (also tried it for PUT and DELETE)

I have configured the request handlers in ejabberd.cfg with the following

{listen,
 [
  (...)
  {5280, ejabberd_http, [
                     http_bind,
                     http_poll,
                     web_admin,
                    {request_handlers, [
                            {["hello_world"], mod_http_hello_world},
                            {["users"], mod_http_registered_users},
                            {["api"],mod_http_rest_api}
                    ]}
   ]}

and the mod_http_rest_api

-module(mod_http_rest_api).
-define(EJABBERD_DEBUG, true).

-behavior(gen_mod).

-export([start/2,stop/1,process/2]).

-include("eja开发者_开发问答bberd.hrl").
-include("jlib.hrl").
-include("ejabberd_http.hrl").

start(_Host, _Opts) ->
  ?INFO_MSG("mod_http_rest_api: Starting",[]),
  ok.

 stop(_Host) ->
   ?INFO_MSG("mod_http_rest_api: Stoping",[]),
   ok.

 process(List,#request{method = Method}) ->
    StrMethod = atom_to_list(Method),
    List ++ " was invoked with method " ++ StrMethod.


At the moment I haven't done either since I can't do rigth now. But the problem seems to be the that the ejabberd server only accepts DELETE and PUT http method after ejabberd 2.1.0 and I am using ejabberd 2.0.5 has is stated in EJAB-662

So to make a DELETE and PUT to work I will need to update ejabberd to 2.1.0 or higher

Another way that seems possible would be using this ejabberd_http_rest.patch.

Edit: I Upgraded my ejabberd to 2.1.6 and now I am able to use the DELETE and PUT HTTP Methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜