Http.Method

The method of an HTTP request, shared by the server and the client side of this package.

Http.Server gives the method of every request it receives as a Method, and Http.Stream takes one for every request it sends. The type has a module of its own so that a program that only sends requests need not import the server module to name a method. The rest of what an HTTP client needs, such as Http.Header and Http.Error, comes from elm/http.

import Http.Method exposing (Method(..))


Http.Method.toString OPTIONS
--> "OPTIONS"
type Method
    = GET
    | HEAD
    | POST
    | PUT
    | DELETE
    | CONNECT
    | OPTIONS
    | TRACE
    | PATCH
    | UNKNOWN String

An HTTP method.

The constructors are the methods of RFC 9110 and PATCH (RFC 5789), spelled as they are sent. UNKNOWN holds the name of any other method, as it was received or is to be sent, for example UNKNOWN "PROPFIND".

toString : Method -> String

Returns the name of a method, for example "GET". UNKNOWN name gives name.

Http.Method.toString PATCH
--> "PATCH"


Http.Method.toString (UNKNOWN "PROPFIND")
--> "PROPFIND"
fromString : String -> Method

Returns the method named name.

Method names are case-sensitive in HTTP, so the name is matched exactly: "GET" gives GET, while "get" gives UNKNOWN "get". Any name that is not one of the constructors gives UNKNOWN name, so fromString and toString give back the name they were given.

Http.Method.fromString "OPTIONS"
--> OPTIONS


Http.Method.fromString "get"
--> UNKNOWN "get"