Api

This module is responsible for communicating to the Conduit API.

Credentials

type Cred

The authentication credentials for the User (that is, the currently logged-in user.)

This includes:

  • The cred's Username
  • The cred's authentication token

By design, there is no way to access the token directly as a String. It can be added to a header to a HttpBuilder for a request, or encoded into local storage, but that's it.

This token should never be rendered to the end user, and with this API, it can't be!

username : Cred -> Username

Return the username stored into the credentials.

HTTP Requests

type alias Request a =
Request a

For convenience, to avoid having to import Api.Endpoint when using Api.

register : Body -> Decoder (Cred -> a) -> Request a

A register request that will decode the credentials into the Cred opaque type.

login : Body -> Decoder (Cred -> a) -> Request a

A login request that will decode the credentials into the Cred opaque type.

get : Endpoint -> Maybe Cred -> Decoder a -> Request a

HTTP GET request.

post : Endpoint -> Maybe Cred -> Body -> Decoder a -> Request a

HTTP POST request.

put : Endpoint -> Cred -> Body -> Decoder a -> Request a

HTTP PUT request.

delete : Endpoint -> Cred -> Decoder a -> Request a

HTTP DELETE request.

It does not require any body as the url is enough to identify the targeted resource.

settings : Cred -> Body -> Decoder (Cred -> a) -> Request a

A user update request that will decode the credentials into the Cred opaque type.

Application

Decoder (Cred -> session)
-> { init : Maybe session -> Url -> Key -> ( model, Cmd msg )
, onUrlChange : Url -> msg
, onUrlRequest : UrlRequest -> msg
, subscriptions : model -> Sub msg
, update : msg -> model -> ( model, Cmd msg )
, view : model -> Document msg
}
-> Program Value model msg

A custom application that knows how to decode the potential credentials from the flags.

Persistence

storeSession : List ( String, Value ) -> Maybe Cred -> Cmd msg

Store the given session fields together with the credentials into local storage.

onSessionChange : (Maybe session -> msg) -> Decoder (Cred -> session) -> Sub msg

An event listener for session changes. It will trigger for any change of the session stored into the local storage, even those from other browser tabs or windows.