Curl -F test with Grape REST endpoint doesn't pass data

I have a Grape REST endpoint served with Puma on localhost:8080. Testing
wth a HTML form does what it should but testing with:

curl -F “day=24;month=3;year=1975” http://localhost:8080/data

… produces an “Invalid Identifier” http response due to null values
being passed to the endpoint instead of the data.

The relevant part of my endpoint contains this:

module Calc
class API < Grape::API
format :json

 post '/data' do
   calc params[:day], params[:month], params[:year]
 end

end
end

gvim

On Nov 27, 2014, at 1:57 AM, gvim [email protected] wrote:

I have a Grape REST endpoint served with Puma on localhost:8080. Testing wth a
HTML form does what it should but testing with:

curl -F “day=24;month=3;year=1975” http://localhost:8080/data

Is this a JSON API?

If so, you need to set the appropriate headers (Content-Type and Accept,
to application/json) and pass the params as a single JSON string using
-d instead of -F.

If you want to simulate the form (i.e. not JSON, Content-Type =
multipart/form-data) then you should specify each parameter with -F
separately.

curl -F “day=24” -F “month=3” -F “year=1975” etc.

HTH,
Ammar

On 27/11/2014 03:44, Ammar A. wrote:

Is this a JSON API?

If so, you need to set the appropriate headers (Content-Type and Accept, to
application/json) and pass the params as a single JSON string using -d instead of
-F.

If you want to simulate the form (i.e. not JSON, Content-Type =
multipart/form-data) then you should specify each parameter with -F separately.

curl -F “day=24” -F “month=3” -F “year=1975” etc.

It only required changing the curl flag in the end. This did everything
I needed:

curl -d “day=24;month=3;year=1975” http://localhost:8080/data

gvim

On Nov 27, 2014, at 7:08 AM, gvim [email protected] wrote:

It only required changing the curl flag in the end. This did everything I
needed:

curl -d “day=24;month=3;year=1975” http://localhost:8080/data

That does work, but note that it’s not a JSON request.

Regards,
Ammar

On Dec 6, 2014, at 8:23 AM, gvim [email protected] wrote:

On 28/11/2014 10:36, Ammar A. wrote:

That does work, but note that it’s not a JSON request.

My Grape app uses format :json so I’m assuming JSON is returned.

It doesn’t seem that it matters for your application, but if you’re
interested, that sets the format of the response your app returns, not
the format of the requests it accepts.

Regards,
Ammar

On 28/11/2014 10:36, Ammar A. wrote:

On Nov 27, 2014, at 7:08 AM, gvim [email protected] wrote:

It only required changing the curl flag in the end. This did everything I
needed:

curl -d “day=24;month=3;year=1975” http://localhost:8080/data

That does work, but note that it’s not a JSON request.

My Grape app uses format :json so I’m assuming JSON is returned.

gvim