Sha256: 4440fa3573b9a8326dad6ecb60e8cc95bc01b6e32a379c2b840d724fca8767e3

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# API wrapper

## Description

This gem is a generic client for HTTP based APIs.

## Installation

You can use this gem in your project by specifying it in your `Gemfile`:

```
gem "api"
```

or simply install it via the CLI:

```
gem install api
```

## Usage

Create your own API client my inheriting from the Api::Client class and defining all mandatory defaults attributes in a Namespace::Default module as such:

```
module ExampleApi
  class Client < Api::Client
    # Include mandatory modules
    include Api::Configurable
    include Api::Connection
    include Api::Authentication
  end

  module Default
    API_ENDPOINT = "http://example.org".freeze

    class << self

      # Include mandatory module
      include Api::DefaultOptions

      def api_endpoint
        API_ENDPOINT
      end

    end
 end
end
```

Now get started requesting stuff from your api:

```
c = ExampleApi::Client.new
 => ...

c.root
 => "<!doctype html>\n..."

c.last_response.data == c.get("/")
 => true

c.get("/boom")
 raises Api::NotFound: #<Sawyer::Response:0x000000029bb908>
```

## License

Code licensed under [MIT-LICENSE](https://github.com/paulrbr/api/blob/master/MIT-LICENSE)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
apii-0.0.4 README.md