# resti

> ```javascript npm install --save resti ```

Latest version **2.1.5** (published 2016-10-06) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.5 |
| Published | 2016-10-06 |
| First published | 2015-01-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ergusto |
| Maintainers | ergusto |

## Links

- npm: https://www.npmjs.com/package/resti
- Repository: https://github.com/ergusto/resti
- Homepage: https://github.com/ergusto/resti#readme
- Issues: https://github.com/ergusto/resti/issues
- npm.io page: https://npm.io/package/resti

## Recent versions

- 2.1.5 (latest) — 2016-10-06
- 2.1.4 — 2016-10-04
- 2.1.3 — 2016-10-04
- 2.1.2 — 2016-10-04
- 2.1.0 — 2016-09-21
- 2.0.9 — 2016-09-20
- 2.0.8 — 2016-09-03
- 2.0.7 — 2016-09-02
- 2.0.6 — 2016-09-02
- 2.0.5 — 2016-09-02
- 2.0.4 — 2016-09-02
- 2.0.2 — 2016-09-02
- 2.0.1 — 2016-09-01
- 2.0.0 — 2016-09-01
- 1.1.6 — 2016-08-31
- … 21 more at https://npm.io/package/resti/versions

## README

# resti

```javascript
npm install --save resti
```

Or grab the script from the [build folder](https://github.com/ergusto/resti/tree/master/build). Documentation can be found [here](docs/index.md).

## Overview


Create resources to interact with REST APIs.

```javascript
// create base resource at URI http://swapi.co/api
var api = new resti('http://swapi.co/api');
```

Build up a resource by using the 'one' and 'many methods', then create and send a request:

```javascript
// resource for multiple starships
api.starships = api.many('starships');

// resource for single starship
var milleniumFalcon = api.starships.one(10);

// sends GET request to http://swapi.co/api/starships/10
milleniumFalcon.get(function(res) {
    if (res.ok)
        doSomethingWithResponse(res.body);
});
```

### Middleware

Use connect/express-like middleware to intercept and respond to requests.

```javascript
api.before(function attachToken(req, next) {
    const token = cookie.load('token');
    // only send request if we have a token
    if (token) {
        req.header('Authorization', token);
        next();
    } else {
        // user's token has expired and must sign in again
        window.location.href = '/login';
    }
});
```

```javascript
api.use(function(res, next) {
    // Flag for 401 HTTP status code.
    if (res.unauthorized) {
        return res.redirect('/unauthorized');
    }
    next();
});
```

Endpoints inherit the middleware of their parents as long as it is defined on the parent before cloning.


## License

MIT

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