https://github.com/cundd/rest-adapter-typescript
Adapter to interface with REST via TypeScript
https://github.com/cundd/rest-adapter-typescript
rest rest-client restful-api typescript typescript-adapter typo3
Last synced: over 1 year ago
JSON representation
Adapter to interface with REST via TypeScript
- Host: GitHub
- URL: https://github.com/cundd/rest-adapter-typescript
- Owner: cundd
- License: mit
- Created: 2018-07-23T10:08:54.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-03-26T11:20:30.000Z (over 6 years ago)
- Last Synced: 2025-01-21T15:11:24.424Z (over 1 year ago)
- Topics: rest, rest-client, restful-api, typescript, typescript-adapter, typo3
- Language: TypeScript
- Size: 160 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TypeScript Adapter for [Cundd Rest](https://rest.cundd.net)
Library to fetch and deserialize objects from a REST API
```typescript
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('Iresults-RealEstate-Person');
promise
.then((foundPersons: Person[])=> {
// Do something with the found records
})
.catch(error => {
// Handle errors
});
```