# arekzc-resource

> Template engine for frontend developers to prototype views

Latest version **0.2.2** (published 2015-10-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install arekzc-resource
pnpm add arekzc-resource
yarn add arekzc-resource
bun add arekzc-resource
```

## 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.2 |
| Published | 2015-10-21 |
| First published | 2015-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+10 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ArekZc |
| Maintainers | arekzc |
| Keywords | rest, api, resource, angular, model, typescript |

## Links

- npm: https://www.npmjs.com/package/arekzc-resource
- Repository: https://github.com/ArekZc/ResourceManager
- Homepage: https://github.com/ArekZc/ResourceManager#readme
- Issues: https://github.com/ArekZc/ResourceManager/issues
- npm.io page: https://npm.io/package/arekzc-resource

## Dependencies (2)

- [angular](https://npm.io/package/angular.md) ^1.4.7
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.2

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.2.2 (latest) — 2015-10-21
- 0.2.1 — 2015-10-21
- 0.1.0 — 2015-10-04

## README

# ResourceManager 
[![Build Status](https://travis-ci.org/ArekZc/ResourceManager.svg)](https://travis-ci.org/ArekZc/ResourceManager)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
> easy to use model based REST API client

## Installation
```sh
npm install arekzc-resource
```

## Example

### Typescript
```javascript
// Model of
@Reflect.metadata('Url', new arekzc.resource.resource.UrlGenerator('/books/{id}'))
class Book {
	
	public id: number;
	
	public title: string;
	
}

// For this example i use angular $http service but you could
// replace it with other with similar interface
let http = angular.injector(['ng']).get('$http');
// Registry for new Resource classes
let registry = new arekzc.resource.registry.ResourceRegistry();
// Create configuration to set defaults for resourceManager service
let configuration = new arekzc.resource.configuration.Configuration(registry);
// Create instance of resource with provided services
let resourceManager = new arekzc.resource.ResourceManager(http, configuration);
// Get new resource based on metadata added by Reflect library
resourceManager.create(Book).get(1);
```

### Javascript

```javascript

function Book() {
	
	this.id = undefined;
	
	this.title = undefined;
}

Reflect.defineMetadata('Url', new arekzc.resource.resource.UrlGenerator('/books/{id}'), Book)
// For this example i use angular $http service but you could
// replace it with other with similar interface
var http = angular.injector(['ng']).get('$http');
// Registry for new Resource classes
var registry = new arekzc.resource.registry.ResourceRegistry();
// Create configuration to set defaults for resourceManager service
var configuration = new arekzc.resource.configuration.Configuration(registry);
// Create instance of resource with provided services
var resourceManager = new arekzc.resource.ResourceManager(http, configuration);

resourceManager.create(Book).get(1);
```

## API

### Metadata

```javascript
// Required: Define route generator used to generate url for http service
// parameters passed in route are fields in model
@Reflect.metadata('Url', new arekzc.resource.resource.UrlGenerator('/books/{id}')
// Optional: Convert response data to provided model
@Reflect.metadata('Converter', new arekzc.resource.converter.ResponseConverter())
// Optional: Convert error response
@Reflect.metadata('ErrorConverter', new arekzc.resource.converter.ResponseErrorConverter())
// Optional: Remove unnecessary fields from request body
// You can use one of defined one Whitelist or Blacklist or create yours
@Reflect.metadata('Filter', new arekzc.resource.filter.Whitelist(['title']))
// Optional: Name of resource used for request
@Reflect.metadata('ResourceName', 'NameOfRegistredResource')
// Optional: Normalize request data fields
@Reflect.metadata('TransformRequest', new arekzc.resource.transform.RequestTransform())
```

### Default resource

```javascript
let resource = resourceManager.create(Book);

let book = new Book();

book.id = 1;
book.title = 'Harry Potter';

resource.save(book);
resource.get(book.id);
resource.query({}, {q: 'Harry'});
resource.update(book);
resource.remove(book);
```

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