i want to POST data to two API_URL.
let say
API1 = api/v1/data1
API2= api/v1/data2
I want to GET STATUS CODE 200 for API1 before i post another data for API2.
How can i do that in Angular2?
i want to POST data to two API_URL.
let say
API1 = api/v1/data1
API2= api/v1/data2
I want to GET STATUS CODE 200 for API1 before i post another data for API2.
How can i do that in Angular2?
A common function to send the HTTP Request
. It will return the response status along with the response data as json:
sendRequest(yourRequest: Request) {
return this.http.request(yourRequest)
.map((res: Response) => {
return { status: res.status, json: res.json() }
}).catch(err => this.tempError(err));
}
Your code to send two requests:
sendRequest(yourFirstRequest).subscribe(data => {
if(data.status == 200) {
sendRequest(yourSecondRequest).subscribe(data => {
//handle the response from the second request.
})
}
})