How to request restful rails application with curl?

here is my problem .. resource: user method: create

I call curl as follows:

curl -X POST -H 'Content-type: text/xml' -d '<xml><login>john</login><password>123456</password></xml>' http://0.0.0.0:3000/users

but the params hashes in rails look like this:

{"xml"=> {"login"=>"luca", "password"=>"123456"}}

I want it to look like this:

{"login"=>"luca", "password"=>"123456"}

I can make it be like this if I pass parameters to url (...? Login = luca & pas ....), but this is not good ...

any idea?

+3
source share
3 answers
curl -X POST -d 'login=john&password=123456' http://0.0.0.0:3000/users

See also: Stack Overflow: How to Make a POST Swirl Request

+3
source
curl -X POST -H 'Content-type: text/xml' -d '<login>john</login><password>123456</password>' http://0.0.0.0:3000/users

What does it mean?

, params [: xml] , params [: login] params [: password]?

@user = User.authenticate(params[:xml])

.

+2

Hey, I had this problem for a long time. I found out that you can do this -

Create a new defaults.rb inside the initializers directory: yourapp / config / initializers / defaults.rb

ActiveRecord::Base.include_root_in_json = false

Now the root should disappear from your json.

+1
source

Source: https://habr.com/ru/post/1714162/


All Articles