# rest-fetch

> a library to fetch graph of rest resources

Latest version **0.2.1** (published 2015-11-29) · (MIT OR Apache-2.0) license · 0 weekly downloads

## Install

```sh
npm install rest-fetch
pnpm add rest-fetch
yarn add rest-fetch
bun add rest-fetch
```

## 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.2.1 |
| Published | 2015-11-29 |
| First published | 2015-11-08 |
| Weekly downloads | 0 |
| License | (MIT OR Apache-2.0) |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | gdefacci |

## Links

- npm: https://www.npmjs.com/package/rest-fetch
- Repository: https://github.com/gdefacci/rest-fetch
- Homepage: https://github.com/gdefacci/rest-fetch#readme
- Issues: https://github.com/gdefacci/rest-fetch/issues
- npm.io page: https://npm.io/package/rest-fetch

## Dependencies (4)

- [flib](https://npm.io/package/flib.md) 0.1.1
- [es6-promise](https://npm.io/package/es6-promise.md) ^3.0.2
- [whatwg-fetch](https://npm.io/package/whatwg-fetch.md) 0.10.0
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) 0.1.2

## Recent versions

- 0.2.1 (latest) — 2015-11-29
- 0.2.0 — 2015-11-15
- 0.1.0 — 2015-11-08

## README

A annotations based typescript library, to fetch graph of objects, exposed as rest/HATEOAS resources. 

tutorial
========

Suppose we have 2 resources, persons and cities, and persons has a subresource address:

```
GET /persons/pippo
```

```json
{
  "name" : "pippo",
  "friends" : [
    "/persons/minni"
  ],
  "address" : "/persons/pippo/address"
}
```

```
GET /cities/RE
```

```json
{
  "name" : "RE"
}
```

```
GET /persons/pippo/address
```

```json
{
  "street" : "dei pomi",
  "city" : "/cities/RE"
}
```

and we want to map those resources to the typescript model:

    interface City {
      name:string
    }

    interface Address {
      street:string
      city:City
    }

    interface Person {
      name:string
      friends:Person[]
      address:Address
    }

We can achieve the result defining few classes:

    import {link, fetch} from "rest-fetch"

    class CityImpl implements City {
      name:string
    }

    class AddressImpl implements Address {
      street:string
      
      @link()
      city:City
    }

    class PersonImpl implements Person {
      name:string
      
      @link({ arrayOf:Person })
      friends:Person[]
      
      @link()
      address:Address
    }

And then:

```
const result:Promise<Person> = fetch(PersonImpl).from("/persons/pippo")  
```

See [tests](src/test) for more examples

It also works for cyclic/recursive structures.

Issues/Limitations
==================

- classes instantiation is done invoking the constructor with no arguments 
- @link() and @convert() annotations can be specified only for properties of classes 
- class declaration order matters, actually you can only reference a previously defined class in link, or convert annotations

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