
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
typescript-rest-mapper
Advanced tools
Package that allows you to automagically build services that consume REST API's. Received/send data is automatically converted between real TypeScript-objects and JSON-objects.
The TypeScript REST Mapper package provides an easy-to-use and efficient way to automatically construct a service, which is capabel of performing REST CRUD-operations. No need to manually perform HTTP-requests, receive results, perform error handling and parse JSON into true TypeScript-objects. You only need to instanciate a new Service, with the correct type of object and you can start consuming REST API's immediatly.
Features:
See our quickstart and start developing with TypeScript REST Mapper right now.
NOTE: This package is still under development, and as a consequence documentation is still under development. I don't think the API will change in the future, but changes are not ruled out.
Latest changes (v1.0.17):
TypeScriptRestMapper is available on NPM, and can be installed using npm install typescript-rest-mapper. Note that you must enable support for decoraters in your tsconfig.json by adding "experimentalDecorators": true and "emitDecoratorMetadata": true to the compilerOptions.
This package exposes a class called Entity. Every TypeScript-class for which JSON-objects are retrieved from an API, should extend the Entity-class. TypeScriptRestMapper exposes 4 different types of decorators, that can be used inside of a class to indicate which properties should be serialised and read for which type of REST-operation.
In the following example, a server returns samples from a url of this format: "http://example.com/samples/id". The result of calling "http://example.com/samples/46" is for example:
{
"id": 46,
"name": "Blub",
"description": "Lorem ipsum dolor sit amet.",
"createdAt": "2019-04-02T11:39:52.927277Z",
"features": [
{
"id": 9,
"name": "CD45RA"
},
{
"id": 11,
"name": "CD4"
}
]
}
A sample contains an array of nested Feature-objects. To be able to query a similar URL, we need to create 2 classes: one for samples and one for features.
Sample:
export default class Sample extends Entity {
@Read() @Store() @Update()
private _name: string = "";
@Read() @Store() @Update()
private _description: string = "";
@Read()
private _createdAt: Date = new Date();
@ReadArray(Feature)
private _features: Feature[] = [];
get name(): string {
return this._name;
}
set name(value: string) {
this._name = value;
}
get description(): string {
return this._description;
}
set description(value: string) {
this._description = value;
}
get features(): Feature[] {
return this._features;
}
set features(data: Feature[]) {
this._features = data;
}
get createdAt() {
return this._createdAt;
}
set createdAt(value: Date) {
this._createdAt = value;
}
}
Feature:
export default class Feature extends Entity {
@Read()
private _name: string;
get name(): string {
return this._name;
}
set name(name: string) {
this._name = name;
}
}
Querying the given API is now as simple as creating a new instance of Service<Sample> and calling the associated retrieve(id) method:
let sampleService = new Service<Sample>(Sample);
let result = await sampleService.retrieve(46);
if (result.successfull) {
let sample: Sample = result.payload;
} else {
console.error("Something went wrong: " + result.errorMessage);
}
The result of this operation is a TypeScript-object of the Sample-class that contains an array of nested Feature-objects.
Full documentation for this package is still under construction. Checkout our wiki in the future for the full documentation.
FAQs
Package that allows you to automagically build services that consume REST API's. Received/send data is automatically converted between real TypeScript-objects and JSON-objects.
We found that typescript-rest-mapper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.