Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/doowb/fly-api

Fly.io API wrapper for simplifying REST calls.
https://github.com/doowb/fly-api

api fly flyio rest-api restful

Last synced: 24 days ago
JSON representation

Fly.io API wrapper for simplifying REST calls.

Awesome Lists containing this project

README

        

# fly-api [![NPM version](https://img.shields.io/npm/v/fly-api.svg?style=flat)](https://www.npmjs.com/package/fly-api) [![NPM monthly downloads](https://img.shields.io/npm/dm/fly-api.svg?style=flat)](https://npmjs.org/package/fly-api) [![NPM total downloads](https://img.shields.io/npm/dt/fly-api.svg?style=flat)](https://npmjs.org/package/fly-api) [![Fly.io Community Slack](https://fly.io/slack/badge.svg)](https://fly.io/slack/)

> Fly.io API wrapper for simplifying REST calls.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save fly-api
```

Install with [yarn](https://yarnpkg.com):

```sh
$ yarn add fly-api
```

## Usage

```js
var Fly = require('fly-api');
```

## API

### [Fly](index.js#L18)

Create a new Fly instance using the given options.

**Params**

* `options` **{Object}**: Options for setting authentication token and api url.
* `options.token` **{String}**: Authentication token for fly.io api.
* `options.url` **{String}**: fly.io api url. Defaults to (https://fly.io/api/v1/)

**Example**

```js
var fly = new Fly({token: 'xxxx'});
```

### [.get](index.js#L51)

Send a GET request to the specified `path` at the fly.io api url.

**Params**

* `path` **{String}**: Path to use after the api url
* `options` **{Object}**: Options
* `cb` **{Function}**: Callback function that takes an `err` and `result` parameters.

**Example**

```js
fly.get('sites/doowb/hostnames', {}, function(err, result) {
if (err) {
console.error(err);
return;
}
console.log(result);
//=> {
//=> "data": {
//=> "attributes": {
//=> "hostname": "foo.doowb.com"
//=> }
//=> }
//=> }
});
```

### [.post](index.js#L90)

Send a POST request to the specified `path` at the fly.io api url.

**Params**

* `path` **{String}**: Path to use after the api url
* `data` **{Object}**: The payload to send in the post.
* `cb` **{Function}**: Callback function that takes an `err` and `result` parameters.

**Example**

```js
var options = {
data: {
attributes: { hostname: 'bar.doowb.com' }
}
};

fly.post('sites/doowb/hostnames', options, function(err, result) {
if (err) {
console.error(err);
return;
}
console.log(result);
//=> {
//=> "data": {
//=> "attributes": {
//=> "hostname": "bar.doowb.com"
//=> }
//=> }
//=> }
});
```

## About

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.

### Building docs

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

### Author

**Brian Woodward**

* [github/doowb](https://github.com/doowb)
* [twitter/doowb](https://twitter.com/doowb)

### License

Copyright © 2017, [Brian Woodward](https://doowb.com).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on August 21, 2017._