elm-lang/http/1.0.0

NOTE: this package moved to elm/http

NOTE: this package is not compatible with Elm 0.19.1

Http.Progress

Track the progress of an HTTP request. This can be useful if you are requesting a large amount of data and want to show the user a progress bar or something.

Here is an example usage: demo and code.

Note: If you stop tracking progress, you cancel the request.

Progress

type Progress data
= None
| Some
{ bytes : Int
, bytesExpected : Int
}
| Fail Error
| Done data

The progress of an HTTP request.

You start with None. As data starts to come in, you will see Some. The bytesExpected field will match the Content-Length header, indicating how long the response body is in bytes (8-bits). The bytes field indicates how many bytes have been loaded so far, so if you want progress as a percentage, you would say:

Some { bytes, bytesExpected } ->
  toFloat bytes / toFloat bytesExpected

You will end up with Fail or Done depending on the success of the request.

track : String -> (Progress data -> msg) -> Request data -> Sub msg

Create a subscription that tracks the progress of an HTTP request.

See it in action in this example: demo and code.