Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lvermeulen/flurl.http.xml

Extension for Flurl.Http to support XML
https://github.com/lvermeulen/flurl.http.xml

flurl xdocument xml

Last synced: 3 days ago
JSON representation

Extension for Flurl.Http to support XML

Awesome Lists containing this project

README

        

![Icon](http://i.imgur.com/llEKpRL.png?1)
# Flurl.Http.Xml
[![Build status](https://ci.appveyor.com/api/projects/status/16qwl13xsaylb450?svg=true)](https://ci.appveyor.com/project/lvermeulen/flurl-http-xml)
[![license](https://img.shields.io/github/license/lvermeulen/Flurl.Http.Xml.svg?maxAge=2592000)](https://github.com/lvermeulen/Flurl.Http.Xml/blob/master/LICENSE)
[![NuGet](https://img.shields.io/nuget/v/Flurl.Http.Xml.svg?maxAge=86400)](https://www.nuget.org/packages/Flurl.Http.Xml/)
![downloads](https://img.shields.io/nuget/dt/Flurl.Http.Xml)
![](https://img.shields.io/badge/.net-4.6.1-yellowgreen.svg)
![](https://img.shields.io/badge/netstandard-2.0-yellowgreen.svg)

XML extension to the excellent [Flurl](https://github.com/tmenier/Flurl) library

## Features:
* Get, post and receive XML models
* Receive XDocument
* Receive XElements with XPath

## Usage:

* Get an XDocument:
~~~~
var result = await "https://query.yahooapis.com/v1/public/yql"
.SetQueryParam("q", "select wind from weather.forecast where woeid=2460286")
.SetQueryParam("format", "xml")
.GetXDocumentAsync();

string chill = result
?.Element("query")
?.Element("results")
?.Element("channel")
?.Element(XNamespace.Get("http://xml.weather.yahoo.com/ns/rss/1.0") + "wind")
?.Attribute("chill")
?.Value;
~~~~

* Post and receive a model:
~~~~
var result = await "http://my_xml_endpoint"
.PostXmlAsync(new TestModel { Number = 3, Text = "Test" })
.ReceiveXml();

Assert.AreEqual(3, result.Number);
Assert.AreEqual("Test", result.Text);
~~~~

* Put a model and receive an XDocument:
~~~~
var result = await "http://my_xml_endpoint"
.PutXmlAsync(new TestModel {Number = 3, Text = "Test"})
.ReceiveXDocument();

Assert.AreEqual("3", result?.Element("TestModel")?.Element("Number")?.Value);
Assert.AreEqual("Test", result?.Element("TestModel")?.Element("Text")?.Value);
~~~~

## Thanks
* [XML File](https://thenounproject.com/term/xml-file/320630/) icon by [Oliviu Stoian](https://thenounproject.com/smashicons/) from [The Noun Project](https://thenounproject.com)