cundd / rest-adapter
TypeScript Adapter for [Cundd Rest](https://rest.cundd.net)
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Language:TypeScript
This package is auto-updated.
Last update: 2024-10-26 21:09:04 UTC
README
Library to fetch and deserialize objects from a REST API
import {AdapterConfiguration, RestAdapter, PropertyTypeOptions, ra_property} from '@cundd/rest-adapter'; export class Person { // Map property `name` 1:1 when converting @ra_property() public name: string; // Convert the input data of `realEstates` into an array of `RealEstate` objects @ra_property(RealEstate, PropertyTypeOptions.Multiple) public realEstates: RealEstate[]; } export class RealEstate { // Use key `street` for property `_street` when converting @ra_property('street') private _street: string; get street(): string { return this._street; } } const rd = new RestAdapter(AdapterConfiguration.fromUrl('http://base.url.tld/rest/')); const promise = rd.findAll<Person>('Iresults-RealEstate-Person'); promise .then((foundPersons: Person[])=> { // Do something with the found records }) .catch(error => { // Handle errors });