使用以下模块定义时
defmodule Router.Folder do
use Maru.Router
namespace :folder do
route_param :id do
get do
IO.puts "ID: " <> params[:id]
json(conn, %{ user: params[:id], msg: "Hello Elixir World!" })
end
params do
requires :name, type: String
end
post do
IO.puts params[:name]
IO.puts params[:token]
IO.puts params[:id]
IO.puts "Posting"
json(conn, %{ msg: "Hello Elixir World!" })
#conn |> text("Hello")
end
end # end route_param :id
end # end namespace :folder
end # end defmodule Router.Folder
defmodule FolderService.API do
use Maru.Router
before do
plug Plug.Logger
plug Plug.Parsers,
pass: ["*/*"],
json_decoder: Poison,
parsers: [:urlencoded, :json]
end
mount Router.Folder
end
我收到这个错误
**(退出)引发异常:
**(Maru.Exceptions.InvalidFormat)解析参数错误:名称
(文件夹)lib/folder.ex:29:FolderService.API.route/2 中的匿名 fn/1
(maru) lib/maru/runtime.ex:25: Maru.Runtime.parse_params/3
(文件夹) lib/folder.ex:29: 匿名 fn/1 in FolderService.API.route/2
(文件夹) lib/folder.ex:29 :FolderService.API 中的匿名 fn/1。error_handler /1
(文件夹)lib/folder.ex:29:FolderService.API.call/2
(文件夹)中的匿名 fn/1 lib/folder.ex:29:FolderService.API 中的匿名 fn/1。错误处理程序/1
(插件) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) src/cowboy_protocol.erl:442::cowboy_protocol.execute/4
运行此curl
命令时:
curl -X POST -H "Content-Type: applicaton/json" -d '{"name": "foobar"}' 'http://localhost:9000/folder/1233'
代码工作正常,但如果我卷曲
curl -X POST -d "name=foobar" 'http://localhost:9000/folder/1233'