TayKangSheng/forem-api/1.0.0

ForemApi.Article

This module allows you to make API calls to fetch an article and decode it into an Elm records.

Definition

type alias Article =
{ typeOf : String
, id : Int
, title : String
, slug : String
, socialImage : String
, description : String
, readingTimeMinutes : Int
, publishedAt : Posix
, user : User
, bodyMarkdown : Maybe String
, bodyHtml : Maybe String
, tags : List String
, url : String
, canonicalUrl : String
}

Representation of an Article record from Forem API. All functions in this module should return an Article record.

API calls

fetch : Config -> Int -> (Result Error Article -> msg) -> Cmd msg

Fetch an article by article's ID.

foremApiConfig : ForemApi.Config
foremApiConfig =
    ForemApi.Config
        "https://dev.to"
        [ Http.header "accept" "application/vnd.forem.api-v1+json" ]


cmd : Cmd msg
cmd =
    ForemApi.Article.fetch foremApiConfig 1208487 msg
fetchBySlug : Config -> String -> String -> (Result Error Article -> msg) -> Cmd msg

Fetch an article using author's username and article's unique slug.

foremApiConfig : ForemApi.Config
foremApiConfig =
    ForemApi.Config
        "https://dev.to"
        [ Http.header "accept" "application/vnd.forem.api-v1+json" ]


cmd : Cmd msg
cmd =
    ForemApi.Article.fetchBySlug foremApiConfig "no_81" "1st-post-2a1" msg

Decoders

articleDecoder : Decoder Article

Decoder to decode article data from Forem Api into an Article record.