Provide Response Code Enums
See original GitHub issueWhat kind of issue is this?
- Feature Request. Start by telling us what problem you’re trying to solve. Often a solution already exists! Don’t send pull requests to implement new features without first getting our support. Sometimes we leave features out on purpose to keep the project small.
I believe this library will benefit from having the Response
object return an Enum
on its method code()
, like many other HTTP libraries and Frameworks do., so instead of:
if (response.code() == 200) {
// print "OK".
} else if (response.code() == 403) {
// print "Forbbiden"
}
In which we have to memorize all the HTTP codes, and maybe mix some, we can have:
if (response.code() == HttpStatus.OK_200) {
// print "OK".
} else if (response.code() == HttpStatus.Forbidden_403) {
// print "Forbbiden"
}
I think this will help the users to code quicker with the library (autocomplete can help with Enums
) and beginners on REST and HTTP codes will be less prone to errors and mixing up what code does what.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Does Java have a complete enum for HTTP response codes?
I'm debugging some Java code that uses javax.ws.rs.core.Response.Status . It works, but it only defines about half of the valid HTTP response ...
Read more >Response.Status (Java(TM) EE 7 Specification APIs)
An enumeration representing the class of status code. Enum Constant Summary. Enum Constants. Enum Constant and Description.
Read more >HttpStatusCode Enum (System.Net) - Microsoft Learn
Equivalent to HTTP status 200. OK indicates that the request succeeded and that the requested information is in the response. This is the...
Read more >status-code-enum - npm
HTTP status codes as a TypeScript enum.. Latest version: 1.0.0, last published: 4 years ago. Start using status-code-enum in your project by ...
Read more >HTTP Status Codes Java - Medium
Anytime an HTTP response is transmitted, a status code is included in the response. HTTP status codes are used to determine if the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If ya want constants there are some here: https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html
I think the code becomes more readable, maybe you guys deal with HTTP codes for a long time and don’t see the difference, but for beginners all those numbers on the middle of the logic can get a bit hard to read smoothly.
Just my $0.2