# slumber

> Port of Python's slumber library -- A library that makes consuming a RESTful API easier and more convenient

Latest version **0.11.0** (published 2017-03-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install slumber
pnpm add slumber
yarn add slumber
bun add slumber
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.11.0 |
| Published | 2017-03-30 |
| First published | 2014-01-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Manfred Touron |
| Maintainers | m42am |
| Keywords | slumber, python, api, request, rest, json, yaml, restful |

## Links

- npm: https://www.npmjs.com/package/slumber
- Repository: https://github.com/moul/node-slumber
- Homepage: https://github.com/moul/node-slumber#readme
- Issues: https://github.com/moul/node-slumber/issues
- npm.io page: https://npm.io/package/slumber

## Dependencies (5)

- [debug](https://npm.io/package/debug.md) ^2.2.0
- [yamljs](https://npm.io/package/yamljs.md) 0.2
- [request](https://npm.io/package/request.md) ^2.72.0
- [querystring](https://npm.io/package/querystring.md) ^0.2.0
- [browser-request](https://npm.io/package/browser-request.md) ^0.3.3

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.11.0 (latest) — 2017-03-30
- 0.10.1 — 2016-07-12
- 0.10.0 — 2016-07-04
- 0.9.0 — 2016-03-24
- 0.8.0 — 2015-11-09
- 0.7.1 — 2015-11-09
- 0.7.0 — 2015-04-21
- 0.6.0 — 2015-04-13
- 0.5.0 — 2014-12-24
- 0.4.1 — 2014-08-07
- 0.3.4 — 2014-04-28
- 0.3.3 — 2014-01-27
- 0.3.2 — 2014-01-17
- 0.3.1 — 2014-01-17
- 0.2.2 — 2014-01-15
- … 10 more at https://npm.io/package/slumber/versions

## README

Slumber (Node.js version)
=========================

[![Build Status](https://travis-ci.org/moul/node-slumber.png?branch=master)](https://travis-ci.org/moul/node-slumber)
[![Dependency Status](https://david-dm.org/moul/node-slumber.png?theme=shields.io)](https://david-dm.org/moul/node-slumber)

![NPM Badge](https://nodei.co/npm/slumber.png?downloads=true&stars=true "NPM Badge")

Port of the Python's [slumber](https://github.com/dstufft/slumber) library in Node.js -- A library that makes consuming a RESTful API easier and more convenient

Node's Slumber is a Node.js library that provides convenient yet powerful object-oriented interface to RESTful APIs.
It acts as a wrapper around the excellent [request](https://github.com/mikeal/request) library and abstracts away the handling of URLs, serialization, and request processing.

QuickStart
----------

1. Install Node's Slumber

    ```bash
    $ npm install slumber
    ```

2. Use Node's Slumber

Usage in CoffeeScript
---------------------

```coffee
slumber = require 'slumber'

# Connect to http://slumber.in/api/v1/ with the Basic Auth user/password of demo/demo
api = slumber.API 'http://slumber.in/api/v1/', { auth: ['demo', 'demo'] }, ->

  # GET http://slumber.in/api/v1/note/
  #     Note: Any kwargs passed to get(), post(), put(), delete() will be used as url parameters
  api('note').get (err, data) ->
    console.log err, data

  # ---

  callback = (err, data) ->
    console.log err, data

  # POST http://slumber.in/api/v1/note/
  new_post = api('note').post({'title': 'My Test Note', 'content': 'This is the content of my Test Note!'}, cb)

  # PUT http://slumber.in/api/v1/note/{id}/
  api('note')(new_post['id']).put({'content': 'I just changed the content of my Test Note!'}, cb)

  # PATCH http://slumber.in/api/v1/note/{id}/
  api('note')(new_post['id']).patch({'content': 'Wat!'}, cb)

  # GET http://slumber.in/api/v1/note/{id}/
  api('note')(new_post['id']).get(cb)

  # DELETE http://slumber.in/api/v1/note/{id}/
  api('note')(new_post['id']).delete(cb)

  api('resource').get {username: "example", api_key: "1639eb74e86717f410c640d2712557aac0e989c8"}, cb

  # GET http://slumber.in/api/v1/note/?title__startswith=Bacon
  api('note').get(title__startswith="Bacon", cb)
```

How to use callbacks
--------------------

`node-slumber` uses a dynamic callback mechanism, based on the arity of the callback.

Depending on the callback arity, you will have:

- with an arity of 1: `function(err)`
- with an arity of 2: `function(err, processedData)`
- with an arity of 3: `function(err, fullRequestResponse, processedData)`

Debug
-----

`node-slumber` uses the [debug](https://www.npmjs.com/package/debug) package.

To enable debug you can use the environment variable `DEBUG=` as :

- `DEBUG='slumber:api' ...` to see debug for `node-slumber` API calls only
- `DEBUG='slumber:*' ...` to see debug for `node-slumber`, more verbose
- `DEBUG='*' node ...` to see debug for all modules using `debug`, extremely verbose

Development
-----------

[![Gitter chat](https://badges.gitter.im/moul/node-slumber.png)](https://gitter.im/moul/node-slumber)

Requirements
------------

- Node.js >= v0.10

See also
--------

* Browse [examples](https://github.com/moul/node-slumber/tree/master/examples) in CoffeeScript and Javascript

License
-------

MIT

---
_Source: https://npm.io/package/slumber · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
