GithubHelp home page GithubHelp logo

sue445 / faraday-mashify Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 54 KB

Faraday middleware for wrapping responses into Hashie::Mash

Home Page: https://sue445.github.io/faraday-mashify

License: MIT License

Ruby 96.22% Shell 3.78%
faraday faradaymiddleware

faraday-mashify's Introduction

Faraday Mashify

CI Gem License

Faraday middleware for wrapping responses into Hashie::Mash.

This very specific middleware has been extracted from the faraday_middleware project.

This is fully compatible with FaradayMiddleware::Mashify

Installation

Add this line to your application's Gemfile:

gem 'faraday-mashify'

And then execute:

bundle install

Or install it yourself as:

gem install faraday-mashify

Usage

curl http://www.example.com/api/me
{"name":"sue445"}
require 'faraday/mashify'

connection =
  Faraday.new(url: 'http://www.example.com') do |conn|
    conn.response :mashify
    conn.response :json
  end

response = connection.get('/api/me').body

response[:name]
#=> "sue445"

response['name']
#=> "sue445"

response.name
#=> "sue445"

Customize response class

If you want to customize the response class, pass mash_class to conn.response :mashify. (default is Hashie::Mash)

e.g.

class MyHash < Hashie::Mash
end

connection =
  Faraday.new(url: 'http://www.example.com') do |conn|
    conn.response :mashify, mash_class: MyHash
    conn.response :json
  end

response = connection.get('/api/me').body

response.class
#=> MyHash

Migrate from faraday_middleware

Please do the following

  1. gem "faraday_middleware" -> gem "faraday-mashify" in Gemfile
  2. require "faraday_middleware" -> require "faraday/mashify"

Development

After checking out the repo, run bin/setup to install dependencies.

Then, run bin/test to run the tests.

To install this gem onto your local machine, run rake build.

To release a new version, make a commit with a message such as "Bumped to 0.0.2" and then run rake release. See how it works here.

Contributing

Bug reports and pull requests are welcome on GitHub.

License

The gem is available as open source under the terms of the MIT License.

faraday-mashify's People

Contributors

dependabot[bot] avatar sue445 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

noma4i

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.