This project was initially created to demonstrate Elm Tasks and their relation to the revamped elm-lang/http library in 0.18.
After that, it is being modified to serve as an example of:
- RemoteData modelling
- Error messages
- Quick grid layout, with fallback See todo.md for more :)
The application tries to find a user's id by their username, and then gets all their photos.
These are the main steps that I came up with for this version of Elm:
Http.send
now performs the task described in the request and sends a message on success. The message has theResult
type, so theOk
, andErr
cases have to be handled (cf. two success/fail messages in 0.17).- In order to chain tasks, we use
Task.andThen
; Task.perform
is now only used for tasks that can't fail. [3]Task.attempt
is now used for Tasks that can fail [4]. The message sent also handles theResult
type'sOk
andErr
cases.- You can see how this aligns with
Http.send
.
- You can see how this aligns with
In the example, note that there is a separate function findUserAndPhotos
that internally uses the declared Http.Request
functions coalesced into Tasks.
This allows each Http.Request
(findUserId
, getPicturesByUID
) to be used either as a task individually or through the new Http.send
If you want to try this out on your own machine, you would need to add an API key, as string, in the respective parts of findUserId
and getPicturesByUID
.
You can do this via the flickr website.
If you don't already have elm
and elm-live
:
npm install -g elm elm-live
Then, to build everything:
elm-live --output=elm.js src/Main.elm --open --debug
Serve index.html
and elm.js
however you want :)
Flickr API use inspired by: https://github.com/toastal/elm-flickr-photo-gallery-demo
MIT © Fotis Papadogeorgopoulos