You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't mind doing it. Just need some high level guidance about your design patterns. Here's an example of an implementation I'm using in a project I'm currently doing:
module Codes
# Informational
OK =200
CREATED =201# Client Error.
BAD_REQUEST =400
UNAUTHORIZED =401end
And then used as
r.status == Codes.OK # true
Adding constants may be outside of the scope of what you're trying to do here and that's totally fine too. Is there a need for a higher level HTTP API?
The text was updated successfully, but these errors were encountered:
Currently, we just have https://github.com/JuliaWeb/HTTP.jl/blob/master/src/status_messages.jl, which allows getting a human-readable status for a status code. I wouldn't mind having a StatusCodes module as you outlined and moving the current STATUS_MESSAGES structure into it. I'd say go ahead w/ a PR and we can review there.
I agree adding a functionality to search a status code from human-readable status would be great for many server applications!!.
Adding status code constants is great, but I think just adding a very simple function like this would be good.
julia> function statuscode(msg)
for pair in pairs(HTTP.Messages.STATUS_MESSAGES)
pair.second == msg && return pair.first
end
throw(ArgumentError("Unknown status message:"*msg))
end
statuscode (generic function with 1 method)
julia> statuscode("OK")
200
julia> statuscode("hoge")
ERROR: ArgumentError: Unknown status message:hoge
Stacktrace:
[1] statuscode(::String) at ./REPL[16]:5
[2] top-level scope at REPL[18]:1
Julia 1.3.0
HTTP.jl 0.8.8
MbedTLS.jl 0.7
Python requests has constants available for HTTP status codes. Does it make sense to add them?
I don't mind doing it. Just need some high level guidance about your design patterns. Here's an example of an implementation I'm using in a project I'm currently doing:
And then used as
Adding constants may be outside of the scope of what you're trying to do here and that's totally fine too. Is there a need for a higher level HTTP API?
The text was updated successfully, but these errors were encountered: