Send an HTTP 201 response using Google Cloud endpoints

I want to send an HTTP 201 response after creating the resource along with its location.

HTTP/1.1 201 Created Location: http://www.example.org/myresource/12546 

How do you define your @ApiMethod ?

+4
source share
1 answer

As stated in the documentation :

HTTP 200 is usually accepted by endpoints if the API method returns successfully. If the response method of the API method is invalid or the API method returns null, HTTP 204 will be set instead. HTTP 2xx codes should not be used in custom exception classes.

stating that if you still need to return the code 201, you can crack the service exception to provide this.

 public class EverythingOKException extends ServiceException { public EverythingOKException(String message) { super(201, message); } } 
+2
source

Source: https://habr.com/ru/post/1488570/


All Articles