Coder Social home page Coder Social logo

klient's Introduction

klient

A REST client library I'm working on. I've only recently started on it and it has a long way to go before it might be worth using.

postcodes.io client example:

# Partial implementation of API for https://api.postcodes.io
class Postcodes
  include Klient
  default_collection_accessor :result

  def initialize
    super("https://api.postcodes.io", content_type: :json, accept: :json)
  end

  collection :postcodes, identifier: :postcode

  resource :random do
    resource :postcodes
  end
end

resource = api.postcodes.get "OX49 5NU"
=> #<Postcodes::Postcodes:70141412425480 @url="https://api.postcodes.io/postcodes">

# Most recent HTTP status for resource:
resource.status_code
=> 200

# Resource delegates method calls down to last response ('result' isn't a
# defined method call: It's just part of the structure of the document that's
# getting returned.):
resource.result.parish
=> "Brightwell Baldwin"

# Postcode bulk lookup. Collection responses are arrays right now, next step is
# to create a collection class that stores headers, allows pagination etc.
results = api.postcodes.post(postcodes: ["OX49 5NU", "M32 0JG", "NE30 1DP"])
=> [#<Postcodes::Postcodes:70243439926840 @url="https://api.postcodes.io/postcodes/OX49%205NU">,
 #<Postcodes::Postcodes:70243439926340 @url="https://api.postcodes.io/postcodes/M32%200JG">,
 #<Postcodes::Postcodes:70243439925820 @url="https://api.postcodes.io/postcodes/NE30%201DP">]

# Gets a random postcode.
resource = api.random.postcodes.get
=> #<Postcodes::Random::Postcodes:70243435956120 @url="https://api.postcodes.io/random/postcodes">
resource.result.postcode
=> "PO20 2WA"

klient's People

Contributors

jfitisoff avatar

Watchers

James Cloos avatar  avatar

klient's Issues

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.