简体   繁体   English

Erlang Cowboy中的冒号

[英]Colon in Erlang Cowboy

I am using leptus , which is based on Cowboy , as a RESTful server. 我将基于Cowboy的 leptus用作RESTful服务器。 I have a problem with router. 我的路由器有问题。

In my code: 在我的代码中:

post("/restconf/operations/nm-restful:create-mp", Req, State) ->
    {200, {json, <<>>, State}.

In Cowboy, when there is a colon, it will do binding. 在Cowboy中,当有冒号时,它将进行绑定。 But what if there is actually a colon in the URL path? 但是,如果URL路径中实际上有一个冒号怎么办? I don't want it be bound. 我不想被束缚。 There's no information on this issue in the official website tutorial. 官方网站教程中没有有关此问题的信息。

I looked at the source of cowboy_router (which leptus uses) and I don't think this is possible. 我查看了cowboy_router (leptus使用的来源)的来源, cowboy_router我认为这是不可能的。 I can't see any way to "escape" a colon in the source. 我看不到任何在源代码中“转义”冒号的方法。 If that's true, your best bet would be to match all such routes using /restconf/operations/:anything and then do a case on the value of the parameter anything inside the function. 如果是这样,您最好的选择是使用/restconf/operations/:anything匹配所有这样的路由,然后对函数内部任何参数的值进行案例分析。 Here's an example: 这是一个例子:

post("/restconf/operations/:thing", Req, State) ->
  case leptus_req:param(Req, thing) of
    <<"nm-restful:create-mp">> ->
      {200, {json, <<>>, State};
    _ ->
      {404, {json, <<>>, State}.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM