How to make http request and decode response to concrete type in Elm 0.17?

ondrej

I want to create a function that will make a request to the server and returns decoded value. I have custom headers within my request so I have to use Http.send function.

So far I was able to create task

getCurrentUser userId authToken err ok =
  let
    request =
      Http.send defaultSettings
        { verb = "GET"
        , headers = [("X-Auth", authToken)]
        , url = "http://os.apiary.com"
        , body = empty
        }

  in
    Task.perform err ok request

type alias User = { name : String, age : Maybe Int }
userDecoder = object2 User ("name" := string) (maybe ("age" := int))

but I don't know where to put decode logic.

Chad Gilbert

I think you're looking for fromJson:

getCurrentUser userId authToken err ok =
  let
    request =
      Http.send defaultSettings
        { verb = "GET"
        , headers = [("X-Auth", authToken)]
        , url = "http://os.apiary.com"
        , body = empty
        }

  in
    Http.fromJson userDecoder request
      |> Task.perform err ok

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to make http request and decode response to concrete type in Elm 0.17?

From Dev

Chain http request and merge json response in ELM

From Dev

How to make an HTTP request without waiting for the response in Ruby

From Dev

how to make a copy of response of http.Get(url) request in Golang

From Dev

How to make HTTP Post request and get the response as JSON Android

From Dev

How to intercept a call from $http and provide a response accordingly to the type of request?

From Java

How to write a test for an http get request in elm

From Dev

Elm : Decode Http.Error

From Dev

Swift make a http request response as array

From Dev

how to get response of http request

From Dev

HTTP Response content type different on HEAD request

From Dev

How it becomes to concrete type?

From Dev

How to make HTTP request with cookie

From Dev

How to make an HTTP request in PHP?

From Dev

How to make HTTP request at an interval?

From Dev

How to make an HTTP request in PHP?

From Dev

How to make HTTP request at an interval?

From Dev

How to make http request in factory

From Dev

How to log HTTP request/response information after the HTTP response is sent?

From Dev

Elm StartApp decoding http request

From Dev

HTTP Request with No HTTP Response

From Dev

HTTP Request with No HTTP Response

From Dev

How to get the type of the HTTP request

From Dev

How to make httpd response 200 for options request?

From Dev

How to make a statistic request without response?

From Dev

How to get full HTTP request (not response) headers

From Dev

Are the letters that make up an HTTP request (and response) in ASCII format?

From Dev

make HTTP request from python and wait a long time for a response

From Dev

how to avoid type field in request and response @jsoninfotype

Related Related

  1. 1

    How to make http request and decode response to concrete type in Elm 0.17?

  2. 2

    Chain http request and merge json response in ELM

  3. 3

    How to make an HTTP request without waiting for the response in Ruby

  4. 4

    how to make a copy of response of http.Get(url) request in Golang

  5. 5

    How to make HTTP Post request and get the response as JSON Android

  6. 6

    How to intercept a call from $http and provide a response accordingly to the type of request?

  7. 7

    How to write a test for an http get request in elm

  8. 8

    Elm : Decode Http.Error

  9. 9

    Swift make a http request response as array

  10. 10

    how to get response of http request

  11. 11

    HTTP Response content type different on HEAD request

  12. 12

    How it becomes to concrete type?

  13. 13

    How to make HTTP request with cookie

  14. 14

    How to make an HTTP request in PHP?

  15. 15

    How to make HTTP request at an interval?

  16. 16

    How to make an HTTP request in PHP?

  17. 17

    How to make HTTP request at an interval?

  18. 18

    How to make http request in factory

  19. 19

    How to log HTTP request/response information after the HTTP response is sent?

  20. 20

    Elm StartApp decoding http request

  21. 21

    HTTP Request with No HTTP Response

  22. 22

    HTTP Request with No HTTP Response

  23. 23

    How to get the type of the HTTP request

  24. 24

    How to make httpd response 200 for options request?

  25. 25

    How to make a statistic request without response?

  26. 26

    How to get full HTTP request (not response) headers

  27. 27

    Are the letters that make up an HTTP request (and response) in ASCII format?

  28. 28

    make HTTP request from python and wait a long time for a response

  29. 29

    how to avoid type field in request and response @jsoninfotype

HotTag

Archive