How to use the multiple parameter in postman - spring-boot

I just want to know that how we can pass multiple variable or parameter in the message body by using the Spring boot.
Want to pass more than two variable in the postman as a parameter.

Spring Boot not support multipe requestbody.

Not sure I understand the question, but there are many ways to pass parameters to an API.
As a JSON object
If you just want to pass multiple parameters you'd just pass them in json format in the request body as a post or a put:
{
"firstName": "bob",
"lastName": "smith",
"middleName": "joe"
}
And your controller method would look something like
public Name createName(
#RequestBody Name name
) {}
As a JSON list
If you mean you have multiple values for the same parameter then you can pass them as a list.
[
{"firstName": "bob"},
{"firstName": "joe"},
{"firstName": "jerry"}
]
And your controller method would look something like
public List<Name> nameList createName(
#RequestBody List<Name> nameList
) {}
or
{
"firstNames": [
{"firstName": "bob"},
{"firstName": "joe"},
{"firstName": "jerry"}
]
}
And your controller method would look something like
public Names createName(
#RequestBody Names names
) {}
In this example Names would be an object that contains a variable
List<Name> nameList;
In the uri
Another option to pass values to the api is to include them a path parameters
from postman your uri would look something like this:
using #RequestParam on the API
http://localhost:8080/apiPath?firstName=bob&lastName=smith&middleName=joe
or
using #PathVariable on the API
http://localhost:8080/apiPath/firstName/bob/lastName/smith/middleName/joe

Related

Retrive additional tag info in json response

When i use get method on the below bright cove api to retrive video meta data, it generates json response with some fields.
"https://cms.api.brightcove.com/v1/accounts/510000340001/videos?sort=-updated_at&limit=1&offset=0"
How do we get additional tags which are not included, say for example 'category' field in the output json response?
I tried to append below in url and api does not detect.
?custom_field=category
If the video has a value set for that field, it will be present in the custom_fields object as below. If the field is empty, it will not be included for that video.
{
"name": "A video",
...
"custom_fields": {
"category": "something"
}
}

How to retrieve single-valued navigation properties for an entity?

I want to update parent relationships for specified entity. The problem is when I query N:1 refs I get referencing attributes that is not always a single-valued navigation property. I do not know how can I distinguish is the attribute parentcustomerid referencing to an account or to a contact entity. So the question is: How can I properly get single-valued navigation property for my specified entity to be able update it using request to PATCH api/data/v9.0/contacts({id}) with the body:
{"single-valued navigation property#odata.bind" :
"/{accounts or contacts}({id})"}
When creating a HTTP Request, add Prefer: odata.include-annotations="*" to your HTTP Request Headers. This way the response not only will have a _[Field Name]_value field with the Id but also a _[Field Name]_value#Microsoft.Dynamics.CRM.lookuplogicalname with the logical name that you look for.
This is an example of a response for a request querying parentcustomerid of a specific contact without the header:
{
"#odata.context": "https://[Organization URI]/api/data/v9.0/$metadata#contacts(_parentcustomerid_value)",
"value": [
{
"_parentcustomerid_value": "bdeb86af-7e1c-e811-a837-000d3ac085f9",
"contactid": "b050f3bb-dbf7-e811-a98a-000d3ac02bae"
}
]
}
And this is an example of a response for the same request with the header added:
{
"#odata.context": "https://[Organization URI]/api/data/v9.0/$metadata#contacts(_parentcustomerid_value)",
"value": [
{
"_parentcustomerid_value#Microsoft.Dynamics.CRM.associatednavigationproperty": "parentcustomerid_account",
"_parentcustomerid_value#Microsoft.Dynamics.CRM.lookuplogicalname": "account",
"_parentcustomerid_value": "bdeb86af-7e1c-e811-a837-000d3ac085f9",
"contactid": "b050f3bb-dbf7-e811-a98a-000d3ac02bae"
}
]
}

SpringBoot: Using #RequestParam and #RequestBody together

It looks like there are a few questions on this topic, but many are now out of date, or are asking reasonably different things.
I am using SpringBoot and the #RestController annotation.
I have a simple use case. I want to send a JSON string to a REST endpoint, that also contains a RequestParameter.
For example, I want to do
curl -d '{ "name": "Joe Bloggs" }' http://localhost:8080/test?debug=Y
I don't want to send the request parameter in the
I have a method signature that accepts both a request parameter and a request body (it's Kotlin, but I don't think that actually makes any difference here).
#PostMapping(value = ["/test"])
fun getGCP(#RequestBody json: String, #RequestParam debug: String) : String
I can access the RequestParam fine, but the RequestBody contains more than just the JSON I have sent through in the body, it contains a merge of the body and the request parameters. In the example above it would output the following for the body binding
debug=Y&{"name": "Joe Blogs"}=
Is there a way that I can simply get the RequestParameter and RequestBody as separate entities?
The problem was the content encoding of the incoming request. Changing the curl command to
curl -H "Content-Type: application/json" -d '{ "name": "Joe Bloggs" }' http://localhost:8080/test?debug=Y
Resulted in my output showing
debug=N
json={ "name": "Joe Bloggs" }

Laravel Api resource controller json format

I managed to change the format for the json response of the laravel resource controller for APIs, i want to make a key -> value response but i cant find the way to remove the brackets:
the response i get is this:
{
"1": [
{
"updated_at": 1536147154
}
],
"2": [
{
"updated_at": 1536160598
}
]
}
but i want it to be like this:
{
"1":
{
"updated_at": 1536147154
},
"2":
{
"updated_at": 1536160598
}
}
I get the response from an eloquent collection, and then I group it by id, but I don't know how to get rid of the brackets because the values end in an array.
I don't know if I am clear in my question.
Solved it, i removed the groupby and instead, I used the keyBy to assign their id as a key.
Transformers can be used to format json
I used https://github.com/spatie/laravel-fractal to format my json response in controllers

transfer a sibling element in a reponse to a parameter in Ready API / SOAP UI

I have one REST endpoint which returns a response like this
[
{
"id": "dbfff519-e8f6-4db3-9e26-a4e9014dc360",
"code": "123456789012345678901234567890123456789012345678901234567890",
"name": "client-code-with-character-length-sixty",
},
{
"id": "a673fb54-3503-4996-ba9b-a4e9014dc3ea",
"code": "18MTH",
"name": "18 Month",
},
{
"id": "60b781e3-4515-40f5-81ee-a4e9014dc400",
"code": "2periods",
"name": "I Have 2 Periods",
}...
etc.
I would like to be able to retrieve the ID where, for example, the code="2periods" UI can retrieve using either ResponseAsxml (with xpath) or Response with JSONPath. If I use the former I have managed to get the following to nearly retrieve my ID
//Response[1]/e[code='2periods']/id
BUT this looks like this
<id>0bc4aa5f-f8ab-4efe-b788-a4e9014dc45f</id>
And I don't know how to remove the start and end tags, the id has to be just the GUID.
I can't work out how to do something similar in the JSONPath - I've only managed to get something like
$[3].id
to work, but the order of the entities is not guaranteed in the test environment.
For ResponseAsXml using the XPath to get only the id value without <id> tag just add /text() to your actual expression:
//Response[1]/e[code='2periods']/id/text()
If you want to do the same using Response property with JSONPath try with:
$..[?(#.['code']=='2periods')].id[0]
Hope it helps,

Resources