I am trying to implement a basic CRUD using the Rest architecture in revel, but I am not able to send the data encoded in json
format to an endpoint, I was try multiple ways to check the body content in the request, so now I have a "minimal compilable example":
create a new project using revel cli tool.
-
Apply the following changes
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
-
do a POST request:
curl --request POST --header "Content-Type: application/json" --header "Accept: application/json" --data '{"name": "Revel framework"}' http://localhost:9000
My problem; the curl call does not give me an echo back (the same json
{"name": "Revel framework"}
), so what I am missing to use revel correctly?
PS: I can find some other related links to this problem but they do not work for me. For example this: https://github.com/revel/revel/issues/126