2

httpResource got released as an experimental feature in Angular 19.2. The httpResource uses the HttpClient under the hood. So I was hoping, I would be able to pass all the options I could pass to the HttpClient to the httpResource as well. However I cannot find anything about the option HttpContext in httpResource. I was wondering if there is a way to still use the context within the httpResource.

I am maintaining an open source library (Github: ng-openapi) and I would like to implement the support for httpResource. However since I am providing the option to have multiple clients and provide an option to add scoped HttpInterceptors, I need to differentiate the fired http requests among the generated clients. For that I used the HttpContext option in HttpClient.

One possible solution would be to add a custom headers. But that would mean my client identifier will also be sent to the server as well. I would like to avoid that (it just feels better). I technically could also remove the added header within the interceptor, but that makes it a bit more complex than necessary. This might be the last solution I would consider, but I really hope I could use the HttpContext.

Appreciate your time and any possible ideas.

PS: does it make sense to add a new tag to SO? (angular-httpresource)

1 Answer 1

2

context is present in the request parameters as you can see here in the v19 docs: https://v19.angular.dev/api/common/http/HttpResourceRequest

Sign up to request clarification or add additional context in comments.

2 Comments

Appreciate the answer. I guess I didn't read it carefully enough. I probably got irritated by the docs as well, since it didn't include context in its options. This was such a headache... Thank you for your help!
Doc probably needs an update, thx for the heads up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.