Closed kates closed 11 months ago
FWIW there's an easier way to implement this. Just type the status
parameter as HTTP::Status | Int32 = :ok
, then pass it to HTTP::Status.new
to normalize everything and call it a day:
require "http/status"
def respond(status : HTTP::Status | Int32 = :ok)
pp HTTP::Status.new status
end
respond # => HTTP::Status::OK
respond HTTP::Status::BAD_REQUEST # => HTTP::Status::BAD_REQUEST
respond 404. # => HTTP::Status::NOT_FOUND
respond :im_a_teapot. # => HTTP::Status::IM_A_TEAPOT
@Blacksmoke16 Thanks a lot for the suggestion! 🙏 This is simpler indeed, definitely the way to go!
@kates could we simplify the PR as suggested by @Blacksmoke16? That way, by using HTTP::Status
in the type restrictions for the status
parameter, we wouldn't need to define a Marten::HTTP::Status
module at all.
Thanks @ellmetha @Blacksmoke16
Taking a shot at adding this feature https://github.com/martenframework/marten/issues/120 using the mapping from https://crystal-lang.org/api/1.9.2/HTTP/Status.html