Sha256: a12964a683ccd151624a8fc5b400bae2f74d67b64d8eb813feaa76d869cefaba

Contents?: true

Size: 1.52 KB

Versions: 55

Compression:

Stored size: 1.52 KB

Contents

# *Flexirest:* XML Responses

Flexirest uses `Crack` to allow parsing of XML responses. For example, given an XML response of (with a content type of `application/xml` or `text/xml`):

```xml
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title>Example Feed</title>
  <link href="http://example.org/"/>
  <updated>2003-12-13T18:30:02Z</updated>
  <author>
    <name>John Doe</name>
  </author>
  <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>

  <entry>
    <title>Atom-Powered Robots Run Amok</title>
    <link href="http://example.org/2003/12/13/atom03"/>
    <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
    <updated>2003-12-13T18:30:02Z</updated>
    <summary>Some text.</summary>
  </entry>

  <entry>
    <title>Something else cool happened</title>
    <link href="http://example.org/2015/08/11/andyjeffries"/>
    <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6b</id>
    <updated>2015-08-11T18:30:02Z</updated>
    <summary>Some other text.</summary>
  </entry>

</feed>
```

You can use:

```ruby
class Feed < Flexirest::Base
  base_url "http://www.example.com/v1/"
  get :atom, "/atom"
end

@atom = Feed.atom

puts @atom.feed.title
puts @atom.feed.link.href
@atom.feed.entry.each do |entry|
  puts "#{entry.title} -> #{entry.link.href}"
end
```

For testing purposes, if you are using a `fake` content response when defining your endpoint, you should also provide `fake_content_type: "application/xml"` so that the parser knows to use XML parsing.


-----

[< Debugging](debugging.md)

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
flexirest-1.12.4 docs/xml-responses.md
flexirest-1.12.3 docs/xml-responses.md
flexirest-1.12.2 docs/xml-responses.md
flexirest-1.12.1 docs/xml-responses.md
flexirest-1.12.0 docs/xml-responses.md
flexirest-1.11.3 docs/xml-responses.md
flexirest-1.11.2 docs/xml-responses.md
flexirest-1.11.1 docs/xml-responses.md
flexirest-1.11.0 docs/xml-responses.md
flexirest-1.10.12 docs/xml-responses.md
flexirest-1.10.11 docs/xml-responses.md
flexirest-1.10.10 docs/xml-responses.md
flexirest-1.10.9 docs/xml-responses.md
flexirest-1.10.8 docs/xml-responses.md
flexirest-1.10.7 docs/xml-responses.md
flexirest-1.10.6 docs/xml-responses.md
flexirest-1.10.5 docs/xml-responses.md
flexirest-1.10.4 docs/xml-responses.md
flexirest-1.10.3 docs/xml-responses.md
flexirest-1.10.2 docs/xml-responses.md