module YourAPIClient exposing (Config, otherFunctions) import Http import Json.Decode as Decode import Json.Encode as Encode -- Config {-| represents the client configuration -} type Config = Config { backend : String , session : Maybe String } {-| returns a client configuration -} config : { backend : String, session : Maybe String } -> Config config params = Config params {-| sets configuration session id -} startSession : String -> Config -> Config startSession session (Config config) = Config { config | session = Just session } {-| clears configuration session id -} clearSession : Config -> Config clearSession (Config config) = Config { config | session = Nothing } {-| returns true if session id is set -} hasSession : Config -> Bool hasSession (Config config) = config.session /= Nothing -- REQUESTS getApples : Config -> Http.Request (List Apple) getApples config = request config { method = "get" , path = "/apples" , query = [] , body = Http.emptyBody , decoder = applesDecoder } ... more requests -- TYPES type alias Apple = { color : String } -- DECODERS appleDecoder : Decode.Decoder Apple appleDecoder = Decode.succeed Apple |: (Decode.field "color" Decode.string) -- REQUEST HELPER request : Config -> { method : String , path : String , query : List ( String, String ) , body : Http.Body , decoder : Decode.Decoder a } -> Http.Request a request (Config config) { method, path, query, body, decoder } = ... get the session token from the config and, if it is present, add it to the http request headers...