0

hi I am new in springboot and I want to develop rest api in springboot. In .net web api IHttpActionresult type used to return entity and httpstatuscode in same time,is there any equivalent in spring boot

Bilgehan
  • 1,135
  • 1
  • 14
  • 41
  • Where is your code? What are you trying to achieve? Do you want to edit the status code of your result? Try `ResponseEntity`. – Airwavezx Feb 06 '19 at 07:09
  • From now I am in learning status ,I want to map my mind how can I do it, in .net public IHttpActionResult Myrestcall(){.... return Ok(myresponse)};I just want to learn is there any java equiavelant of this – Bilgehan Feb 06 '19 at 08:25

1 Answers1

0

Use Spring's Class ResponseEntity<T>. It allows you to add an Object and a Response Status and send to the user. Example from ResponseEntity docs:

HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setLocation(location);
responseHeaders.set("MyResponseHeader", "MyValue");
return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED);

You see how ResponseEntity accepts the body of the response as its first argument, the headers of the response as the second and the HTTP status as the third.

Airwavezx
  • 898
  • 5
  • 14
  • 26