How to pass object as a query param in spring data REST - spring

I am having a EmailRepository which queries for a person like follows
findByPerson(Person person);
The spring-data-rest /search resource list the following href
http://localhost:8080/emailAddresses{?person}
How to make a curl command for the above search url in GET method? Also if the person does not exists, I need to throw "PersonNotFoundException".
I am using org.springframework.boot:spring-boot-starter-data-rest:jar:1.3.3.RELEASE

Try the below curl commands -
if you are using path param -
curl -i -X GET -H "Content-Type: application/json" -H "Cache-Control: no-cache" -k "http://localhost:8080/emailAddresses/person"
if you are using query param -
curl -i -X GET -H "Content-Type: application/json" -H "Cache-Control: no-cache" -k "http://localhost:8080/emailAddresses?person=aaa"

Related

Cannot import Jelastic Manifest with cURL command using two -H parameters

I'm trying to create a Jelastic Manifest with a cURL command inside it. When I import it, it gives me an error but unfortunately I have no access to the console (disabled by the provider).
The command is the following :
curl -X POST <my_url> -H "Content-Type: application/json" -H "Authorization: Bearer <token>" -d "{}"
Some additionnal information :
The URL is correct 100%
The token does not contain any special characters : Only upper/lowercase characters and numbers
The command is run successfully from the command line
If I remove the first -H parameter, I can import my manifest. Same if I remove the second -H parameter and keep the first one
My guess is that, somehow, having two -H is not considered as valid but I don't know why. Any ideas ?
EDIT : A screenshot of the error shown on the platform
The "two -H parameters" wasn't a root cause in your question.
The thing is that the YAML gets the data you sent as a key/value array (dictionary).
In your example it would be:
curl -s -X POST https://test.com -H "Content-Type - as a key,
and
application/json" -H "Authorization: Bearer xx" -d "{\"Key\":\"Value\"}" - as a value.
If you need an array of strings the YAML may be as this
cmd [cp]:
- 'curl -s -X POST https://test.com -H "Content-Type: application/json" -H "Authorization: Bearer xx" -d "{\"Key\":\"Value\"}"'
If you need a multi-line string it should look like this
cmd [cp]: |
curl -s -X POST https://test.com -H "Content-Type: application/json" -H "Authorization: Bearer xx" -d "{\"Key\":\"Value\"}"

API Platform - Dev - all requests return empty result

I have set up API platform and am trying to test the API using curl, eg.
curl -X POST -H "Content-Type: application/json" http://localhost/authentication_token -d '{"email":"test#test.com","password":"the_new_password"}'
curl http://localhost/docs
I am getting no response from the server, always blank.
Requests needed to be HTTPS, as it seems HTTP requests are simply thrown away / ignored. Add the -k flag since the certificate will be self signed and CURL will error out.
curl -X POST -H "Content-Type: application/json" https://localhost/authentication_token -d '{"email":"test#test.com","password":"the_new_password"}' -k
curl https://localhost/docs -k

Kill a YARN application through REST api return Unauthorized by remote user dr.who

curl -u hadoop:123456 -H "Accept: application/json" -H "Content-type: application/json" -v -X PUT -d '{"state": "KILLED"}' "http://host:8088/ws/v1/cluster/apps/application_1575020200992_1673895/state"
I was already add the username and password, but return:
Unauthorized attempt to kill appid application_1575020200992_1673895 by remote user dr.who
What's dr.who ?
I figure out... add the user.name query string parameter.
like this:
curl -u hadoop:123456 -H "Accept: application/json" -H "Content-type: application/json" -v -X PUT -d '{"state": "KILLED"}' "http://host:8088/ws/v1/cluster/apps/application_1575020200992_1673895/state?user.name=hadoop"
http://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/HttpAuthentication.html

Get curl http code

I have the following cURL request. I want to get the http_code, but I want in a different variable, because otherwise it messes with parsing the JSON response from the GET call.
Is there anyway to do this?
curl --write-out %{http_code} --silent --output GET --header "Accept: application/json" --header "URL"
Just use command substitution to store status code in a variable:
status=$(curl --write-out %{http_code} --silent --output tmp.out GET --header "Accept: application/json" --header "URL")
data=$(<tmp.out)
# check status now
declare -p status
# check data
declare -p data
curl -i -H "Accept: application/json" "server:5050/a/c/getName{"param0":"Arvind "}"
curl -w 'RESP_CODE:%{response_code}' -s -X POST --data '{"asda":"asd"}' http://example.com --header "Content-Type:application/json"|grep -o 'RESP_CODE:[1-4][0-9][0-9]'
response=$(curl -sb -H "Accept: application/json" "http://host:8080/some/resource") For response just try $response
Try this following may be this could help you to find the solution https://gist.github.com/sgykfjsm/1dd9a8eee1f70a7068c9

How to insert data into HBase through StarGate REST API

According to the StarGate documentation, this is how a CURL command should look like:
% curl -H "Content-Type: text/xml" --data '[...]' http://localhost:8000/test/testrow/test:testcolumn
This is what I'm trying:
% curl -X POST -H "Accept: text/xml" --data '[<CellSet><Row key="cm93MQ=="><Cell column="dGl0bGU6YQ==">d29ya2Vk</Cell></Row></CellSet>]' http://localhost:8080/test/row1/title
Keep getting HTTP 415, Unsupported Media Type.. any ideas what I'm missing there?
Your current curl options specify you'd like XML output, and curl is assuming you are posting url-encoded form data (and specifying the wrong Content-Type in the HTTP headers).
Amend your -H "Accept: text/xml" to -H "Content-Type: text/xml" and you should be good

Resources