restアーキテクチャを使用してrevelで基本CRUDを実装しようとしていますが、json
フォーマットでエンコードされたデータをエンドポイントに送信できません。リクエストのボディコンテンツをチェックしてください。これで、私は「最小のコンパイル可能なサンプル」を持っています:revel goフレームワークに投稿されたボディを取得できません
revel cliツールを使用して新しいプロジェクトを作成してください。
は以下のものを適用POSTリクエストを行う
diff --git a/app/controllers/app.go b/app/controllers/app.go index 1e94062..651dbec 100644 --- a/app/controllers/app.go +++ b/app/controllers/app.go @@ -9,5 +9,6 @@ type App struct { } func (c App) Index() revel.Result { - return c.Render() + defer c.Request.Body.Close() + return c.RenderJSON(c.Request.Body) } diff --git a/conf/routes b/conf/routes index 35e99fa..5d6d1d6 100644 --- a/conf/routes +++ b/conf/routes @@ -7,7 +7,7 @@ module:testrunner # module:jobs -GET / App.Index +POST / App.Index # Ignore favicon requests GET /favicon.ico 404
を変更します。
curl --request POST --header "Content-Type: application/json" --header "Accept: application/json" --data '{"name": "Revel framework"}' http://localhost:9000
私の問題を。カールコールは私にエコーバック(同じjson
{"name": "Revel framework"}
)を与えないので、正しくrevelを使うのに欠けているのは何ですか?
PS:私はこの問題の他の関連するリンクを見つけることができますが、私にとってはうまくいきません。例えばこのために:https://github.com/revel/revel/issues/126