Project

async-rest

0.05
Low commit activity in last 3 years
No release in over a year
A library for RESTful clients (and hopefully servers).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
 Dependencies

Development

>= 0
~> 3.6

Runtime

 Project Readme

Async::REST

Roy Thomas Fielding's thesis Architectural Styles and the Design of Network-based Software Architectures describes Representational State Transfer which comprises several core concepts:

  • Resource: A conceptual mapping to one or more entities.
  • Representation: An instance of a resource at a given point in time.

This gem models these abstractions as closely and practically as possible and serves as a basis for building asynchronous web clients.

Development Status

Installation

Add this line to your application's Gemfile:

gem 'async-rest'

And then execute:

$ bundle

Or install it yourself as:

$ gem install async-rest

Usage

Generally speaking, you want to create a representation class for each remote resource. This class is responsible for negotiating content type and processing the response, and traversing related resources.

DNS over HTTP

This simple example shows how to use a custom representation to access DNS over HTTP.

require 'async/http/server'
require 'async/http/endpoint'

require 'async/rest/resource'
require 'async/rest/representation'

module DNS
	class Query < Async::REST::Representation
		def initialize(*arguments)
			# This is the old/weird content-type used by Google's DNS resolver. It's obsolete.
			super(*arguments, wrapper: Async::REST::Wrapper::JSON.new("application/x-javascript"))
		end
		
		def question
			value[:Question]
		end
		
		def answer
			value[:Answer]
		end
	end
end

URL = 'https://dns.google.com/resolve'
Async::REST::Resource.for(URL) do |resource|
	# Specify the representation class as the first argument (client side negotiation):
	query = resource.get(DNS::Query, name: 'example.com', type: 'AAAA')

	pp query.metadata
	pp query.value
end

Contributing

We welcome contributions to this project.

  1. Fork it.
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin my-new-feature).
  5. Create new Pull Request.