1 | # docker-remote-api
|
2 |
|
3 | Basic http wrapper to call the docker remote api from node
|
4 |
|
5 | ```
|
6 | npm install docker-remote-api
|
7 | ```
|
8 |
|
9 | [![build status](http://img.shields.io/travis/mafintosh/docker-remote-api.svg?style=flat)](http://travis-ci.org/mafintosh/docker-remote-api)
|
10 |
|
11 | ## Usage
|
12 |
|
13 | ``` js
|
14 | var docker = require('docker-remote-api')
|
15 | var request = docker('/var/run/docker.sock')
|
16 |
|
17 | request.get('/images/json', {json:true}, function(err, images) {
|
18 | if (err) throw err
|
19 | console.log('images', images)
|
20 | })
|
21 |
|
22 | request.get('/images/json', function(err, stream) {
|
23 | if (err) throw err
|
24 | // stream is a raw response stream
|
25 | })
|
26 | ```
|
27 |
|
28 | ## API
|
29 |
|
30 | #### `request = docker([remote], defaults)`
|
31 |
|
32 | `remote` should be an address to a docker instance i.e. `/var/run/docker.sock` or `127.0.0.1:2375`.
|
33 | `defaults` will be used as default values for `get`, `post`, `put`, `delete`.
|
34 |
|
35 | If you omit the `remote` it will be set to `$DOCKER_HOST`
|
36 |
|
37 | #### `request.get(path, [options], cb)`
|
38 |
|
39 | Send a `GET` request to the remote api. `path` should be the request path i.e. `/images/json`.
|
40 | `options` can contain the following
|
41 |
|
42 | ``` js
|
43 | {
|
44 | qs: {foo:'bar'}, // set querystring parameters
|
45 | headers: {name: '...'}, // set request headers
|
46 | json: true, // return json instead of a stream
|
47 | timeout: 20000, // set request timeout
|
48 | version: 'v1.12' // set explicit api version
|
49 | }
|
50 | ```
|
51 |
|
52 | #### `request.delete(path, [options], cb)`
|
53 |
|
54 | Send a `DELETE` request. Similar options as `request.get`
|
55 |
|
56 | #### `post = request.post(path, [options], cb)`
|
57 |
|
58 | Send a `POST` request. Similar options as `request.get` except it returns a request stream
|
59 | that you can pipe a request body to. If you are sending json you can set `options.json = body`
|
60 | and `body` will be stringified and sent as the request body.
|
61 |
|
62 | #### `put = request.put(path, [options], cb)`
|
63 |
|
64 | Send a `PUT` request. Similar options as `request.put`
|
65 |
|
66 | ## License
|
67 |
|
68 | MIT |
\ | No newline at end of file |