Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any method to get constant for HTTP GET, POST, PUT, DELETE? [duplicate]

For example, HttpServletResponse has the HTTP status codes as constants like

public static final int SC_OK = 200; public static final int SC_CREATED = 201; public static final int SC_BAD_REQUEST = 400; public static final int SC_UNAUTHORIZED = 401; public static final int SC_NOT_FOUND = 404; 

Is there any such constants defined for HTTP methods like GET, POST, ..., anywhere in the Java EE API so that it could be referenced easily, rather than creating one on my own?

like image 894
daydreamer Avatar asked Sep 25 '13 15:09

daydreamer


People also ask

Which of the following are HTTP methods?

The primary or most commonly-used HTTP methods are POST, GET, PUT, PATCH, and DELETE. These methods correspond to create, read, update, and delete (or CRUD) operations, respectively.

What is difference between Get Post put Delete methods?

The POST method submits an entity to the specified resource, often causing a change in state or side effects on the server. The PUT method replaces all current representations of the target resource with the request payload. The DELETE method deletes the specified resource.

Which of the following is a best way to create named constants in Java?

The public|private static final TYPE NAME = VALUE; pattern is a good way of declaring a constant.

Which type of variable keeps a constant value once it is assigned?

A constant is a variable whose value cannot change once it has been assigned. Java doesn't have built-in support for constants. A constant can make our program more easily read and understood by others. In addition, a constant is cached by the JVM as well as our application, so using a constant can improve performance.


1 Answers

If you are using Spring, you have this enum org.springframework.web.bind.annotation.RequestMethod

public enum RequestMethod {   GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, TRACE; } 

EDIT : Here is the complete list of constants values in Java 6 You can see that some of those are available in the class HttpMethod but it contains less values than RequestMethod.

public @interface HttpMethod {   java.lang.String GET = "GET";   java.lang.String POST = "POST";   java.lang.String PUT = "PUT";   java.lang.String DELETE = "DELETE";   java.lang.String HEAD = "HEAD";   java.lang.String OPTIONS = "OPTIONS";    java.lang.String value(); } 
like image 158
Arnaud Denoyelle Avatar answered Oct 06 '22 01:10

Arnaud Denoyelle