https://github.com/AlexWayfer/faraday-encode_xml
Faraday middleware for encoding requests as XML
https://github.com/AlexWayfer/faraday-encode_xml
Last synced: 3 months ago
JSON representation
Faraday middleware for encoding requests as XML
- Host: GitHub
- URL: https://github.com/AlexWayfer/faraday-encode_xml
- Owner: AlexWayfer
- License: mit
- Created: 2021-09-21T20:13:46.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-14T11:11:04.000Z (4 months ago)
- Last Synced: 2025-03-23T23:51:30.774Z (3 months ago)
- Language: Ruby
- Size: 106 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-faraday - encode_xml - encode XML requests (responses decoding is included in `faraday_middleware` gem) (Middleware)
README
# Faraday Encode XML
[](https://cirrus-ci.com/github/AlexWayfer/faraday-encode_xml)
[](https://codecov.io/gh/AlexWayfer/faraday-encode_xml)
[](https://codeclimate.com/github/AlexWayfer/faraday-encode_xml)
[](https://depfu.com/repos/github/AlexWayfer/faraday-encode_xml)
[](https://rubygems.org/gems/faraday-encode_xml)
[](LICENSE.txt)This repo is a [Faraday](https://github.com/lostisland/faraday) middleware for encoding requests as XML.
Faraday is an HTTP client library that provides a common interface for making requests.## Installation
Add this line to your application's Gemfile:
```ruby
gem 'faraday-encode_xml'
```And then execute:
```shell
bundle install
```Or install it yourself as:
```shell
gem install faraday-encode_xml
```## Usage
```ruby
require 'faraday/encode_xml'connection = Faraday.new do |faraday|
## This gem only encodes requests
faraday.request :xml## For responses deconding use `faraday_middleware` gem and such code:
# require 'faraday_middleware'
# faraday.response :xml## For example `httpbingo` responses as JSON, so let's enable it:
require 'faraday_middleware'
faraday.response :json
endresponse = connection.post('https://httpbingo.org/post', { a: 1, b: 'foo', c: true })
puts response.body['data'] ## => 1footrue
```### Gyoku options
The middleware uses [`gyoku` gem](https://rubygems.org/gems/gyoku) for XML encoding.
You can pass options for it:
```ruby
connection = Faraday.new do |faraday|
## https://www.rubydoc.info/gems/gyoku/#array-values
faraday.request :xml, gyoku_options: { unwrap: true }
end
```## Development
After checking out the repo, run `bundle install` to install dependencies.
Then, run `bundle exec rspec` to run the tests.
To install this gem onto your local machine, run `toys gem install`.
To release a new version, run `toys gem release %version%`.
See how it works [here](https://github.com/AlexWayfer/gem_toys#release).## Contributing
Bug reports and pull requests are welcome on [GitHub](https://github.com/AlexWayfer/faraday-encode_xml).
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).