Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ymtszw/elm-http-xml
Generates HTTP request for XML API
https://github.com/ymtszw/elm-http-xml
elm elm-lang http xml
Last synced: about 1 month ago
JSON representation
Generates HTTP request for XML API
- Host: GitHub
- URL: https://github.com/ymtszw/elm-http-xml
- Owner: ymtszw
- License: bsd-3-clause
- Created: 2017-12-06T17:13:13.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-15T11:41:50.000Z (over 5 years ago)
- Last Synced: 2024-10-13T20:21:04.196Z (3 months ago)
- Topics: elm, elm-lang, http, xml
- Language: Elm
- Homepage: http://package.elm-lang.org/packages/ymtszw/elm-http-xml/latest
- Size: 10.7 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-http-xml
Generates HTTP request for XML API. Can be used with [`elm/http`][http].
Using [`ymtszw/elm-xml-decode`][exd] for decoding XML response into Elm values.
[http]: http://package.elm-lang.org/packages/elm/http/latest
[exd]: http://package.elm-lang.org/packages/ymtszw/elm-xml-decode/latest## Basic Example
```elm
import Http
import Http.Xml
import Xml.Decode exposing (..)type alias Data =
{ string : String
, integers : List Int
}type Msg = XmlApiResponse (Result Http.Error Data)
getXml : Cmd Msg
getXml =
Http.get
{ url = "https://example.com/data.xml"
, expect = Http.Xml.expectXml XmlApiResponse dataDecoder
}dataDecoder : Decoder Data
dataDecoder =
map2 Data
(path [ "path", "to", "string" ] (single string))
(path [ "path", "to", "int", "list" ] (list int))-- Use with customization
trickyGetXml : Cmd Msg
trickyGetXml =
Http.riskyRequest
{ method = "GET"
, headers = [ Http.header "Accept" "application/xml" ]
, url = "https://example.com/data.xml"
, body = Http.emptyBody
, expect = Http.Xml.expectXml XmlApiResponse dataDecoder
, timeout = Nothing
, tracker = Nothing
}```
## Upgrade from 1.x to 2.x
- It now supports `elm/[email protected]`, which drops `Http.Request` data type. As a result, there is no interface to nicely add `Accept: application/xml` header.
**You have to add the header** if your target servers rigorously require them.
- Probably the most reasonable interface which should take `Accept` header values are `Http.Expect`.
- See this issue: https://github.com/elm/http/issues/54## License
BSD-3-Clause