adamkewley / jobson

A platform for transforming command-line applications into a job service.
Apache License 2.0
256 stars 20 forks source link

Unable to submit via api #3

Closed michaelluich closed 6 years ago

michaelluich commented 6 years ago

I'm trying to submit the trivial job via the API. I keep getting {"code":415,"message":"HTTP 415 Unsupported Media Type"}

To create: $ ./jobson generate spec trivial $ ./jobson validate spec trivial $ ./jobson generate request trivial > dummy-req.json $ curl --data @dummy-req.json --user devops.user:'12!Pass345' localhost:8080/v1/jobs {"code":415,"message":"HTTP 415 Unsupported Media Type"}

$ cat dummy-req.json { "spec" : "trivial", "name" : "Enim dolores vel exercitationem omnis et velit ea autem.", "inputs" : { "message" : "Hello, world!" } }

adamkewley commented 6 years ago

I believe this is because curl defaults to using application/x-www-form-urlencoded as the Content-Type for a request if a Content-Type is not explicitly specified (add -v to curl to confirm for yourself).

I tried a fresh workflow and found that curl worked fine after adding a Content-Type header to tell the server it's JSON:

#/bin/bash

mkdir $1
cd $1
jobson new
jobson generate spec test-spec
jobson generate request test-spec > req.json
jobson users add user -p password
jobson serve config.yml 1>log 2>log &

# Echoes 'Unsupported Media Type'
curl --user user:password --data @req.json localhost:8080/v1/jobs

# Echoes job response
curl -H 'Content-Type: application/json' --user user:password --data @req.json localhost:8080/v1/jobs 
adamkewley commented 6 years ago

I have updated README.md in the master branch with the above example, just in case other devs encounter a similar issue. The response being generated, Unsupported Media Type, is handled by the framework I'm using (dropwizard/jersey). There might be scope for enhancing the error message along the lines of Unsupported Media Type ${type}, but if it involves adding media switches onto each resource it might be too much work right now.

michaelluich commented 6 years ago

That makes sense. It wasn't clear that jobson api needed json. It makes sense but this makes it clearer.

And I can confirm the change works. And that my jobson works as well. Now on to my integration.

curl -H 'Content-Type: application/json' --data @dummy-req.json --user username:password localhost:8080/v1/jobs {"id":"4ejtcuvpr3","_links":{}}

Thanks, Mike Luich

On Thu, Jan 11, 2018 at 4:59 AM, Adam Kewley notifications@github.com wrote:

I have updated README.md in the master branch with the above example, just in case other devs encounter a similar issue. The response being generated, Unsupported Media Type is handled by the framework I'm using (dropwizard/jersey), but there might be scope for enhancing the error message along the lines of Unsupported Media Type ${type}.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/adamkewley/jobson/issues/3#issuecomment-356884867, or mute the thread https://github.com/notifications/unsubscribe-auth/AQ6LBOOnTXv-RISIrAZVP-jZiOTqPhIqks5tJdtygaJpZM4RZu_L .

-- http://www.actifio.com/ Michael Luich Senior Devops Engineer e michael.luich@actifio.com c 7817907586 t @actifio http://twitter.com/actifio Access your enterprise data as a service, instantly anywhere.

adamkewley commented 6 years ago

No problem. I hope your integration goes well.

If you encounter any more issues, keep them coming! =)