Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Access HTTP Header response inside NGRX Effect Angular

In my Angular application upon successfully making a POST to the server I receive a 201 response containing a location in the response headers that I wish to access inside my NGRX Effects. The location contains an id which I need in another effect to trigger a service call.

enter image description here

NGRX ACTION:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

export const postJobOfferSuccess = createAction('[JobOffer] Post jobOffer success', props<{ successMessage: string, publish: boolean, final: boolean, response: HttpHeaderResponse }>());

NGRX EFFECT:

postJobOffer$ = createEffect(() =>
    this.actions$.pipe(
        ofType(postJobOffer),
        mergeMap(action => {
            return this.jobOfferClientService.postJobOffer(action.jobOffer).pipe(
                map((response) => postJobOfferSuccess({ successMessage: 'Success', publish: action.publish, final: action.final, response: response.HttpHeaderResponse })),
                mapErrorToAction(postJobOfferFailed)
            );
        })
    )
);

I would expect my postJobOfferSuccess to contain a response with the HTTPHeaderResponse, however upon inspecting my redux tab it does not show the header response. How can I access HTTPHeaderResponse inside an effect?

my redux tab:

enter image description here

>Solution :

In your service you have to listen to the response :


this.http.post('http//...', payload, { observe: 'response' }).pipe(
  tap(res => console.log(res)) // headers = res.headers | data = res.body
);

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading