divyesh-apihandler-amnex
v1.0.2
Published
This library is authored by Divyesh Patel.
Downloads
27
Readme
Author
This library is authored by Divyesh Patel.
ReactiveApiHandler
ReactiveApiHandler is an Angular service for handling reactive API requests.
Installation
You can install ReactiveApiHandler via npm:
$ npm install divyeshpatelreactiveapihandleramnexUsage
This is a simple example to understand how to use ReactiveApiHandler Here You make a async function and make a call in api in any request so you receive a response in reactive fashion and if your api is fail the {success : false} is print here
async On() {
const payload = {
name: 'book',
desc: 'book',
publisher: 'book',
author: 'book',
};
//get Request
this.subscription = this.eventStreamService
.getMessage()
.subscribe((message: any) => {
console.log(message);
this.cdr.detectChanges();
});
await this.eventStreamService.GetReactiveHandler(
'http://localhost:8000/api/v1/books',
""
);
this.subscription.unsubscribe();
//post request
this.subscription = this.eventStreamService
.getMessage()
.subscribe((message: any) => {
console.log(message);
});
await this.eventStreamService.PostReactiveHandler(
payload,
'http://localhost:8000/api/v1/getGtPointDbname',
""
);
this.subscription.unsubscribe();
//put
this.subscription = this.eventStreamService
.getMessage()
.subscribe((message: any) => {
console.log(message);
this.messages.push(message);
});
await this.eventStreamService.PutReactiveHandler(
payload,
'http://localhost:8000/api/v1/book/4',
""
);
this.subscription.unsubscribe();
// delete request
this.subscription = this.eventStreamService
.getMessage()
.subscribe((message: any) => {
console.log(message);
});
await this.eventStreamService.DeleteReactiveHandler(
'http://localhost:8000/api/v1/book/5',
""
);
this.subscription.unsubscribe();
}API Reference
postReactiveHandler(payload: any, url: string, token: string)
Handles the POST request for a reactive API.
payload: The data to send in the request body.
url: The API endpoint URL.
token: The authorization token.
getMessage(): Observable<JSON>
Returns an Observable to listen for messages from the reactive API.
getReactiveHandler(url: string, token: string)
Handles the GET request for a reactive API.
url: The API endpoint URL.
token: The authorization token.
putReactiveHandler(payload: any, url: string, token: string)
Handles the PUT request for a reactive API.
payload: The data to send in the request body.
url: The API endpoint URL.
token: The authorization token.
deleteReactiveHandler(url: string, token: string)
Handles the DELETE request for a reactive API.
url: The API endpoint URL.
token: The authorization token.
License
This project is licensed under the MIT License - see the LICENSE file for details.
