Http POST requests on Heroku running Springboot app - spring-boot

I've successfully deployed my Springboot app on Heroku. I'm also able to make get request like :
curl GET 'heroku-url'
Correctly returns :
{"id":1,"user_id":1,"title":"rneptdqxen","image":"","price":0.0,"description":"Niente"}
but not POST, if I try this :
curl -X POST 'heroku-url -d '{}' '
An error is thrown :
empty string within braces in URL position 49
If I change heroku-url to 127.0.0.1:8080/..., build Springboot app locally then POST request works so I think that the request is correct, probably I'm missing something about quotes.

please try
curl -X POST -d '{}' 'heroku-url'

Related

Authentication OAuth2 to API REST using cURL

i'm having a little problem here. I've been trying to authenticate (protocol OAuth2) to a REST API using the cURL command. I use the following command line :
curl -X POST -d "client_id=login_id&client_secret=password&grant_type=client_credentials" http://localhost:9001/rest/oauth/token
But it doesn't work and the command returns :
{"status":"error","message":"Parameter is required for method Load."}
But I don't know parameter they are talking about. Do you have any idea where the problem could come from ?

GET works through postman, but returns org.springframework.web.HttpMediaTypeNotSupportedException in CLI

Using spring I wrote a method that should return an array of json objects when GET is called. I checked through PostMan everything works, but when I try to do the GET using curl I get
{"timestamp":1503570488519,"status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Unsupported Media Type","path":"/audpro/report"}
This is the address for postman localhost:8080/audpro/report
My curl command
curl -X GET "http://localhost:8080/audpro/report" -H "accept:application/json"
Why is that?

Curl command not uploading file contents

Hi I am using cURL command to upload a file which is a POST request to my local machine service.
I am using following commands to upload
curl -i -X POST -H "Content-Type: multipart/form-data" -F
"/Users/myName/Folder/file.csv" http://localhost:port/api/fileupload
In my application side I am using spring frameworks web binding to receive the file
Following is the code snippet
public ResponseEntity importDimensions(#RequestBody MultipartFile file) {
// file is variable is always null
}
What am I missing here?
You need an # sign before the filename, like this: #/Users/myName/Folder/file.csv.
And if your server-side code is expecting a parameter named file then you need to do this:
-F "file=#/Users/myName/Folder/file.csv"

Load GeoJSON file into Apache CouchDB

I am working on Windows10 and tried to load a geojson file into my couchdb via the "curl" command and a POST request in the cmd which looks like that:
C:\Program Files\cURL\bin>curl -d #path-to-my-data\data.geojson -H "Content-type: application/json" -X POST http://127.0.0.1:5984/_utils/database.html?-dbName-
and then I get the following error:
{"error":"method_not_allowed","reason":"Only GET,HEAD allowed"}
On http://couchdb-13.readthedocs.org/en/latest/api-basics/ it is said, that "If you use the an unsupported HTTP request type with a URL that does not support the specified type, a 405 error will be returned, listing the supported HTTP methods."
When I try that with a PUT request, I get the same error.
I validated the json with jsonlint so this should not be the problem.
I tried several tutorials like "Three Steps to CouchDB Heaven …" or "Export & Import a Database with CouchDB" but none of them seems to work.
So I am not sure, where the problem is. Do I need to make changes in my geojson file, or something else?
thanks for your help
The needed curl command just looks like that:
curl -H "Content-Type: application/json" -X POST http://localhost:5984/db -d #C:\Users\Name\Desktop\data.geojson

GitHub issue creation API

I'm trying to create an issue with a GitHub repository:
curl -d '{"title":"my-new-repo","body":"my new issue description"}' https://api.github.com/repos/np98765/BattleKits/issues
This just returns:
{
"message": "Not Found"
}
I'm authenticating like this:
curl -u "user:password" https://api.github.com
What am I doing wrong?
http://developer.github.com/v3/issues/#create-an-issue
You don't seem to call POST in your curl request.
You could at least try (following "REST-esting with cURL"):
curl -X POST -i -d '{"title":"my-new-repo","body":"my new issue description"}' https://api.github.com/repos/np98765/BattleKits/issues
With -i for having a look at the response headers.
Just tried curl -u "$REPORTER":"$TOKEN" https://api.github.com/repos/$OWNER/$REPO/issues -d #$JSON_WITH_ISSUE and it worked.
This uses token authentication and reporter is my user, while owner of the repo is the user to whom I'm reporting the issue.

Resources