How to make Get Request with Request param in Postman
I didn't find any solution but the reason is because + is a special character in a URL escape for spaces. Thats why it is replacing + with a " " i.e. a space.
So apparently I have to encode it from my front-end
I want to send a List(which is a member of an object) from Postman to Spring REST API
Having no information about the Controller
class you're using, the first thing I'd assume is that you're receiving an empty object, which means that Spring simply skipped the serialization. This is the case when you don't specify the parameter of the method as @RequestBody
. First, make sure that you do have the annotation.
@RestController
@RequestMapping("/")
public class TestController {
@RequestMapping(value = "/test", method = RequestMethod.POST)
public ResponseEntity test(@RequestBody ChatDescriptionDto dto) {
System.out.println(dto);
return ResponseEntity.ok().build();
}
}
If that's not the case, I'd assume that the problem is with the content type you're using. Spring uses JSON by default, but you can change it in your endpoint's configuration.
How to pass String array in @RequestParam in REST GET API call through POSTMAN or DHC REST application?
First of all, your current method does not work because your @PathVariable
is wrong. In your @RequestMapping
you have the following placeholder in your path: {me_userId}
, which means that it will be mapped to a path variable with that name.
However, the only @PathVariable
you have is nameless, which means it will use the name of the parameter (userId) in stead.
So before you try to execute your request, you have to change your @RequestMapping
into:
@RequestMapping(
value = "/api/getApplication/{userId}", // <-- it's now {userId}
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
Then, if you run the application, you can kinda choose how you want to pass your parameters. Both the following will work:
?fieldNames[]=test,test2
Or:
?fieldNames[]=test&fieldNames[]=test2
Both these results should print the desired results.
I am using Postman, to pass the data to a REST api but my variable is showing null value
I think you can use query strings and path variables.
If you declare a controller's method like:
@GetMapping(path="/invoices")
public String invoiceReceived(@RequestBody Map<String,Object> invoice, @RequestParam String format) {
...
}
the url to which the request is send and the JSON request body will be something like below.
The url:
http://localhost:8080/invoices?format=html
The JSON request body:
{
"invoiceId":"23642",
"clientName":"Client",
"amount":"23742.67",
"email":"client@abc.com"
}
Also you can use a path variable like:
http://localhost:8080/invoices/html
@GetMapping(path="/invoices/{format}“)
public String invoiceReceived(@RequestBody Map<String,Object> invoice, @PathVariable String format) {
...
}
Related Topics
How to Display Auto-Configuration Report When Running a Spring Boot Application
How to Convert a One-Dimensional Array to Two-Dimensional Array in Java
How to Scroll Scrollbar Horizontally Which Is Inside a Window Using Java
How to Get the Average of a 2D Array
How to Update Only the Incoming Fields in a Model Using Spring Data Jpa
Java.Lang.Classcastexception: [Ljava.Lang.Object; Cannot Be Cast to Classname
Setonclicklistener() on a Null Object Reference Error
Shifting Characters Within a String
How to Use If-Else Logic in Java 8 Stream Foreach
Error: Incompatible Types: Int[][] Cannot Be Converted to Int
Wrong Answer in Task - Mistake in Algorithm
How to Send Image With Post Request
How to Check If a Json Key Exists
Arraylist: How Does the Size Increase
I Want to Detect the End of Scroll Event
Convert Localdatetime to Localdatetime in Utc