Skip to content

Commit

Permalink
Update readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Apr 8, 2024
1 parent c088c54 commit 47fa76e
Showing 1 changed file with 2 additions and 54 deletions.
56 changes: 2 additions & 54 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,11 @@ This gem models these abstractions as closely and practically as possible and se

[![Development Status](https://github.com/socketry/async-rest/workflows/Test/badge.svg)](https://github.com/socketry/async-rest/actions?workflow=Test)

## Installation

Add this line to your application's Gemfile:

``` ruby
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.

``` ruby
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')
Please see the [project documentation](https://socketry.github.io/async-rest/) for more details.

pp query.metadata
pp query.value
end
```
- [Getting Started](https://socketry.github.io/async-rest/guides/getting-started/index) - This guide explains the design of the `async-rest` gem and how to use it to access RESTful APIs.

## Contributing

Expand Down

0 comments on commit 47fa76e

Please sign in to comment.